1. class InjectionToken
1.1 InjectionToken
作用
创建在 DI provider 使用的token
Creates a token that can be used in a DI Provider.
1.2 InjectionToken
的类定义
export declare class InjectionToken<T> {
protected _desc: string;
readonly ngInjectableDef: never | undefined;
constructor(_desc: string, options?: {
providedIn?: Type<any> | 'root' | null;
factory: () => T;
});
toString(): string;
}
1.3 InjectionToken
的使用
const BaseURL = new InjectionToken<string>('des:base url');
const injector =
Injector.create({providers: [{provide: BaseURL, useValue:}]})
https://ithelp.ithome.com.tw/articles/10208630?sc=iThelpR
网友评论