我正在学习 Angular 6 的 MEAN 堆栈应用程序。在这里,我想在添加新的客户端/汽车/司机/预订或更新新的客户端/汽车/司机/预订后刷新组件。但是添加新值后,显示所有值的组件不会更新或刷新(当时无法看到当前值),但是当我在组件之间路由然后返回到它更新并显示的同一组件时所有的值。
我希望当从对话框表单添加或更新值时,它会在那时显示。
这是add client component
export class AddClientComponent implements OnInit {
clientForm: FormGroup;
constructor(private fb: FormBuilder,
private clientService: ClientService,
private toastr: ToastrService,
private router: Router,
public dialogRef: MatDialogRef < AddClientComponent > ) {
this.clientForm = this.fb.group({
'clientname': new FormControl(""),
'clientphoneno': new FormControl(""),
'clientemail': new FormControl(""),
'clientaddress': new FormControl("")
});
}
ngOnInit() {
this.router.navigate(['/admin/clients']);
}
saveClient(formdata: any) {
let theForm = this.clientForm.value;
this.clientService.addClient(theForm).subscribe(data => {
if (data.success === false) {
this.toastr.error(data.message);
} else {
this.toastr.success(data.message); …Run Code Online (Sandbox Code Playgroud)