admin管理员组

文章数量:1278854

I'm getting this error on my Angular 7 app and I don't know why. 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. Nothing is changed, I'm still receiving the same error.

I'm getting this error on my Angular 7 app and I don't know why. 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. Nothing is changed, I'm still receiving the same error.

Share Improve this question edited Aug 20, 2021 at 10:00 Guerric P 31.8k6 gold badges58 silver badges105 bronze badges asked Dec 17, 2018 at 10:24 DeooKDeooK 5453 gold badges8 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

ngModel has to be specified on the input, not on the mat-form-field. The only purpose of mat-form-field is to apply some Material CSS

make sure you have MatFormFieldModule and MatInputModule imported in your app.module.ts and also declared in @NgModule({... imports:[MatFormFieldModule,MatInputModule, ...],...}

本文标签: javascriptAngular 7No value accessor for form control with unspecified name attributeStack Overflow