我有一个模板驱动的表单,希望将更改保存为值更改。
HTML:
<form #myForm="ngForm">
...
</form>
组件:
...
@ViewChild('myForm') myForm: NgForm;
...
constructor(private myService: MyService) { }
ngAfterViewInit() {
let form = this.myForm;
this.myForm.form
.valueChanges
.pipe(...)
.subscribe((data) => {
// this.myForm is undefined
// form is undefined
this.myService.save(data);
});
}
在subscribe
中,我无法访问对表单的引用。有什么想法吗?