gpt4 book ai didi

angular - 形式 Angular 6 的 ngModelChange

转载 作者:太空狗 更新时间:2023-10-29 18:18:42 30 4
gpt4 key购买 nike

angular 5升级到6之后

我尝试更新我的表单:

anguar 5 我有:

 <select [ngModel]="toto" (ngModelChange)="onChange($event)" 

<option *ngFor="let toto of totos" [ngValue]="toto.id">{{toto.libelle}}</option>

</select>

angular 6 我更新了:

 <select #oldValue="ngModel" [(ngModel)]="toto" (ngModelChange)="onChange(oldValue)" 

<option *ngFor="let toto of totos" [ngValue]="toto.id">{{toto.libelle}}</option>
</select>

我得到了这个错误:

compiler.js:215 Uncaught Error: Template parse errors:
There is no directive with "exportAs" set to "ngModel" ("

我的 app.component.ts 中有 FormsModule

我忘记了什么?谢谢你

最佳答案

在你的组件中是否有一个名为“toto”的变量名,如果它存在......好的

一个是您需要正确关闭打开的选择标签。

当您使用 [(ngModel)] 时,您需要在 forrm 元素中设置名称

关于angular - 形式 Angular 6 的 ngModelChange,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50488083/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com