I have an Angular component that implements ControlValueAccessor
, but the writeValue
method is never called with the initial value from ngModel
.
template:
<my-comp [(ngModel)]="$ctrl.activeUser"></my-comp>
the component is downgraded to AngularJS via:
.directive('myComp', downgradeComponent({
component: MyComp,
inputs: [],
outputs: [],
}));
I tried adding ngModel
to inputs
and outputs
but it's not working.
You should use ng-model
attribute instead of [(ngModel)]
, like this: <my-comp ng-model="$ctrl.activeUser"></my-comp>
From the angular docs:
* 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">`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With