Angular · Middle · Question 66 of 75
How do you give an InjectionToken a default value without adding providers?
export const PAGE_SIZE = new InjectionToken<number>('PAGE_SIZE', {
providedIn: 'root',
factory: () => 20,
});- ✓Correct answer: Use the
factoryoption withprovidedIn: 'root' - 2Set
defaultValuein@Injectable - 3Tokens always need an explicit provider
Explanation
The factory can call inject() for other dependencies. Any provider for the token still overrides the default.