令牌 InjectionToken and Injec

2019-12-09  本文已影响0人  晨曦Bai

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

2. Inject

上一篇 下一篇

猜你喜欢

热点阅读