首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用什么代替ngModel?

用什么代替ngModel?
EN

Stack Overflow用户
提问于 2022-05-02 18:56:00
回答 1查看 232关注 0票数 -1

我写了这个component.html:

代码语言:javascript
运行
复制
<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>

但在控制台上得到了以下警告:

代码语言:javascript
运行
复制
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.

我对角很陌生。有一个简单的解决办法吗?

EN

Stack Overflow用户

发布于 2022-05-02 19:00:15

对于进一步的查询,您不应该将ngModel与反应性表单一起使用,如果表单不复杂且没有很多逻辑,请阅读https://angular.io/guide/reactive-forms。您可以只使用ngmodel而不使用反应性表单。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72091138

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档