What is multi True provider in angular?

Rupesh Kumar Tiwari
2 min readJul 15, 2019

--

What is multi True provider in angular?

Multi: true means that one provider token provides an array of elements. Using multi: true we tell Angular that the provider is a multi provider. This is used mostly in those scenarios where we use primitives or chunk of values.

Generally we do not use it in injecting the array of classes, but there are some use cases in framework where we do. Let’s understand with one real world example. Suppose we are using two services pricing service and sales service. In sales we are doing order and in pricing we are charging for that order. Both of them have their own configs and at one place we want to put all configs together, this is the place where we use multi: true. So when we need multiple strings to be passed as a single array, then we use multi: true.

To get more details, please visit our video Multi True Provider | mulTitrue | Angular DI Tutorial

As we mentioned earlier with multi providers, we can provide multiple values for a single token in DI. Usually, when we register multiple providers with the same token the last one wins.
For example all directives for router support routerLink, routerOutlet 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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Rupesh Kumar Tiwari
Rupesh Kumar Tiwari

Written by Rupesh Kumar Tiwari

Pluralsight Author, Developer and Trainer. I help students and professionals to become Full Stack Software Developer in less than a Year.

No responses yet

What are your thoughts?