I have a custom input component which implements ControlValueAccessor with providers declared as follows. It seems to work fine. In all the tutorials I could find on the internet, forwardRef was being used extensively whenever NG_VALUE_ACCESSOR is provided
Is it safe to send the following code to production ?
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: CustomInputComponent, //Notice I omitted forwardRef here and it works fine
multi: true
}]
forwardRef
enables Angular to inject a dependency before it is defined. In this case, if this providers array is defined inside the @Component
decorator for a custom input component as you mentioned, it will work since decorators are applied after the class is defined.
Basically, you can remove forwardRef
as long as you are only using it to reference a component inside the decorator for that same component.
See here for in depth reading
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