I'm creating a component implementing ControlValueAccessor to be used in a Reactive Form, it's just a wrapper of an input element with some pipe on it.
I've injected the NgControl in order to retrieve the valid/invalid state and propagate them to the inner input element.
When the input value is found in another input, it is invalid.
On Stackblitz is working fine, but when I to an ng build --prod it raises the error:
ERROR in : No provider for NgControl ("[ERROR ->])
Do you see any problems?
Thanks!
Hello you can add "@Optional" Decorator for your NgControl. It will use null if it cant find a provider. For more information look at: https://angular.io/api/core/Optional
In your Code:
import { Component, Input, OnInit, Self,Optional } from '@angular/core';
...
constructor(
@Self() @Optional() private controlContainer: NgControl
) {
this.controlContainer.valueAccessor = this;
}