【发布时间】:2017-05-10 11:58:21
【问题描述】:
正如您在这个 plunkr (https://plnkr.co/edit/3EDk5xxSLRolv2t9br84?p=preview) 中看到的那样,我有两个选择:一个在主要组件中正常运行,另一个在自定义组件中,继承 ngModel 设置。
以下代码将 innerNgModel 链接到组件 ngModel。
ngAfterViewInit() {
//First set the valueAccessor of the outerNgModel
this.ngModel.valueAccessor = this.innerNgModel.valueAccessor;
//Set the innerNgModel to the outerNgModel
//This will copy all properties like validators, change-events etc.
this.innerNgModel = this.ngModel;
}
它有效,因为 name 属性由两个选择更新。
但是,当它第一次加载时,第二个选择没有选择。
我想我错过了一些东西,一种用初始值初始化 innerNgModel 的方法。
【问题讨论】:
标签: forms angular angular-ngmodel