angular - 形式 Angular 6 的 ngModelChange

标签 angular forms angular6

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/

相关文章:

SignalR SSE 握手失败

Angular : how to call finally() with RXJS 6

node.js - 在客户端和服务器 Mongoose 模型之间共享 typescript 接口(interface)

Angular CLI 和 Angular 版本的区别

node.js - 如何避免 npm install/update 意外?

angular - ng-bootstrap DatePicker 在触发器 Angular 4 上设置 startDate 和 minDate

javascript - jQuery 检查是否填写必填字段的最佳方式

html - playframework,输入禁用中断 Play 传递值?

php - 如何使输入类型标签的必需属性仅适用于特定按钮?

Angular 6 库 - 无法解析条目