我写了这个component.html:
<mat-form-field>
<mat-label>Genre</mat-label>
<mat-select [(ngModel)]="selectedGenre" required formControlName="genre">
<mat-option>--</mat-option>
<mat-option *ngFor="let item of genre | keyvalue" [value]="item.key">{{ item.key }}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field *ngIf="selectedGenre">
<mat-label>Choose a Sub Genre</mat-label>
<mat-select formControlName="subgenre">
<mat-option *ngFor="let sub of genre.get(selectedGenre)" [value]="sub">{{ sub }}</mat-option>
</mat-select>
</mat-form-field>
但在控制台上得到了以下警告:
It looks like you're using ngModel on the same form field as formControlName.
Support for using the ngModel input property and ngModelChange event with
reactive form directives has been deprecated in Angular v6 and will be removed
in a future version of Angular.
我对角很陌生。有一个简单的解决办法吗?
发布于 2022-05-02 19:00:15
对于进一步的查询,您不应该将ngModel与反应性表单一起使用,如果表单不复杂且没有很多逻辑,请阅读https://angular.io/guide/reactive-forms。您可以只使用ngmodel而不使用反应性表单。
https://stackoverflow.com/questions/72091138
复制相似问题