I was looking at the angular 2 validator file . Can someone explain the syntax after "new InjectionToken"? I know its a generic type but how do you understand it?
new InjectionToken<Array<Validator|Function>>('NgValidators');
I was looking at the angular 2 validator file . Can someone explain the syntax after "new InjectionToken"? I know its a generic type but how do you understand it?
new InjectionToken<Array<Validator|Function>>('NgValidators');
Your token can take the following type
Array<Validator|Function>
it means array of Validator
or Function
where Validator
is a class that implements Validator
interface:
export interface Validator {
validate(c: AbstractControl): ValidationErrors|null;
registerOnValidatorChange?(fn: () => void): void;
}
InjectionToken gives you type checking benefit when getting a dependency through injector instance
See also