From the course: Angular Essential Training (2019)
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
The @Inject decorator - Angular Tutorial
From the course: Angular Essential Training (2019)
The @Inject decorator
- [Instructor] Constructor injection of class types can be done with a bit of TypeScript and that's it. To get value types injected into constructors Angular needs a bit more help. Let's create a value provider for our app to store some lookup lists and provide them at Bootstrap. In the app dot module dot ts file, we can add a local variable named lookup lists and set it to an object literal, with a property for mediums. To add the value to the provider, we need to add it to the list of providers in the module metadata. But to do that for a value provider we need to use a different syntax to add it to the providers array. We can add a provider object literal as an array entry here. The provider object literal needs a property named provide, that gets set to either a type, or a String literal. For our lookup lists, we can set it to a String literal of lookup list token. And then it needs the value to use. We can…