[英]Angular 7 - No value accessor for form control with unspecified name attribute
I'm getting this error on my Angular 7 app and I don't know why. 我在Angular 7应用程序中遇到此错误,我不知道为什么。 Even with some researches it seems that this error doesn't make sense.
即使进行了一些研究,似乎该错误也没有道理。
This is what I have: 这就是我所拥有的:
<mat-form-field>
<input matInput placeholder="Name" name="name" [(ngModel)]="data.name" [disabled]="inputReadonly" ngDefaultControl >
</mat-form-field>
I've tried with and withoud ngDefaultControl on mat-form-field and/or input, with and without the name attribute and to move [(ngModel)] on input. 我已经尝试过在mat-form-field和/或输入上使用ngDefaultControl,并且不使用name属性,并在输入上移动[(ngModel)]。 Nothing is changed, I'm still receiving the same error.
什么都没改变,我仍然收到相同的错误。
ngModel
has to be specified on the input
, not on the mat-form-field
. ngModel
必须在input
指定,而不是在mat-form-field
。 The only purpose of mat-form-field
is to apply some Material CSS mat-form-field
的唯一目的是应用一些Material CSS
请确保您有MatFormFieldModule
和MatInputModule
在进口app.module.ts
并在声明@NgModule({... imports:[MatFormFieldModule,MatInputModule, ...],...}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.