What is multi provider in angular2

后端 未结 4 1886
逝去的感伤
逝去的感伤 2020-12-29 18:34

I understand that provider is for getting service from another class but what is multi-provider and token thing?

And also when we do multi=true ?

<
4条回答
  •  粉色の甜心
    2020-12-29 19:11

    multi: true means that one provider token provides an array of elements. For example all directives for router support routerLink, router-outlet are provided by ROUTER_DIRECTIVES.
    If a new provider is registered with the token ROUTER_DIRECTIVES, then it overrides the previously registered directives. If multi: true (on the first registered and the new provider) is set, the new directives are added to the previously registered directives instead of overriding.

    When ROUTER_DIRECTIVES is injected (constructor(@Inject(ROUTER_DIRECTIVES) directives) {}) an array of directive instances is injected. It usually doesn't make sense to inject ROUTER_DIRECTIVES. I used it just as an example because it is multi: true.

提交回复
热议问题