So i was looking at the angular core files, I'm a bit confused on how these four pieces of code connect?
- Code for injection token which is a class
export class InjectionToken extends OpaqueToken {
private _differentiate_from_OpaqueToken_structurally: any;
constructor(desc: string) { super(desc); }
toString(): string { return `InjectionToken ${this._desc}`; }
}
- Code for NG_VALIDATORS which uses the injection token
export const NG_VALIDATORS = new InjectionToken>('NgValidators');
- Required validator which uses the NG_VALIDATORS
export const REQUIRED_VALIDATOR: Provider = {
provide: NG_VALIDATORS,
useExisting: forwardRef(() => RequiredValidator),
multi: true
};
@Directive({
...
}) export class RequiredValidator implements Validator {
//Code here
}
I am having problem tracing back the code from the declaration of REQUIRED_VALIDATOR to injection token. I understand about most of the basic elements but not sure how the "useExisting" is being used for RequiredValidator class (i understand forwardRef). And how NG_VALIDATORS gets benefited, which itself being a constant by definition