美文网首页
令牌 InjectionToken and Injec

令牌 InjectionToken and Injec

作者: 晨曦Bai | 来源:发表于2019-12-09 10:59 被阅读0次

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

相关文章

网友评论

      本文标题:令牌 InjectionToken and Injec

      本文链接:https://www.haomeiwen.com/subject/bfvqwctx.html