我不知道为什么表单不起作用! 输入不会更改表单中的值。
并且 valueChanges
未检测到任何内容。 有什么帮助吗?
应用于 stackblitz: https://stackblitz.com/edit/angular-ivy-w68v69?file=src/app/app.component.ts
import { Component, VERSION } from "@angular/core";
import { FormControl, FormGroup, Validators } from "@angular/forms";
@Component({
selector: "my-app",
template: `
<form [formGroup]="form">
<input
FormControlName="patientName"
placeholder="Enter Patient Name ..."
/>
</form>
`,
styleUrls: ["./app.component.css"]
})
export class AppComponent {
form: FormGroup;
ngOnInit() {
this.form = new FormGroup({
patientName: new FormControl("")
});
this.form.get("patientName").valueChanges.subscribe(x => console.log(x));
this.form.valueChanges.subscribe(next => {
console.log("valueChanges didtted");
console.log(next);
});
console.log("form created");
}
}
最佳答案
HTML 部分中的属性 FormControlName
应该包含小写的“F”:formControlName="patentName"
。
如果你更正这个,它就会起作用:https://stackblitz.com/edit/angular-ivy-cjntrr?file=src/app/app.component.ts
关于javascript - Angular 形式没有检测到值的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66507116/