[英]How to implement ControlValueAccessor on downgraded Angular component
我有一个实现ControlValueAccessor
的Angular组件,但是从未使用ngModel
的初始值调用writeValue
方法。
模板:
<my-comp [(ngModel)]="$ctrl.activeUser"></my-comp>
该组件通过以下方式降级为AngularJS:
.directive('myComp', downgradeComponent({
component: MyComp,
inputs: [],
outputs: [],
}));
我尝试将ngModel
添加到inputs
和outputs
但无法正常工作。
您应该使用ng-model
属性而不是[(ngModel)]
,如下所示: <my-comp ng-model="$ctrl.activeUser"></my-comp>
从角度文档:
* 3. `ng-model` is controlled by AngularJS and communicates with the downgraded Angular component
* by way of the `ControlValueAccessor` interface from @angular/forms. Only components that
* implement this interface are eligible.
*
* ## Supported Features
*
* - Bindings:
* - Attribute: `<comp name="World">`
* - Interpolation: `<comp greeting="Hello {{name}}!">`
* - Expression: `<comp [name]="username">`
* - Event: `<comp (close)="doSomething()">`
* - ng-model: `<comp ng-model="name">`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.