官术网_书友最值得收藏!

Overriding constants

Not everything, though, is a class that needs to be resolved; sometimes it is a constant. For those cases, instead of using useClass, we can use useValue, like so:

providers: [ { provide: 'a-string-token', useValue: 12345678 } ]

This is not really a class type, so you can't write this in a constructor:

constructor(a-string-token) . // will not compile

That wouldn't compile. What we can do instead is to use the @Inject decorator in the following way:

constructor( @Inject('a-string-token') token) // token will have value 12345678

The useValue is no different from useClass when it comes to how to override it. The difference is of course that we need to type  useValue in our instruction to override rather than useClass.

主站蜘蛛池模板: 仁寿县| 福州市| 进贤县| 神池县| 潞城市| 香河县| 阿拉尔市| 乡宁县| 马公市| 腾冲县| 沅陵县| 云和县| 河津市| 江川县| 漳平市| 香港| 方山县| 玛曲县| 洞头县| 纳雍县| 南京市| 黑河市| 平果县| 张家口市| 岐山县| 五河县| 平舆县| 卓尼县| 新巴尔虎左旗| 亚东县| 江源县| 靖安县| 花垣县| 绵阳市| 三台县| 买车| 密山市| 顺昌县| 靖安县| 石楼县| 焉耆|