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.

Injection token

Injection token - Angular Tutorial

From the course: Angular Essential Training (2019)

Start my 1-month free trial

Injection token

- [Tutor] So the inject decorator, with its string literal works. But there's a better way to do this. Relying on string literals for tokens, is always a bit of a risk. They are harder to maintain, easier to mistype, and code editors don't have much opportunity to keep track of them, to aid in refactoring. Angular has a solution for this. It's called an injection token. You can use an injection token, to tell angular you want to have a concrete type that can be passed around. Let's refactor little lookup lists value type, to use an injection token. First, let's create a new file called providers.Ts in the app folder. And we'll move the lookup list value instantiation, from the app module Ts file, into this new file. The provider metadata property in the app module, is going to need this lookup list variable. So that's have the export keyword in front of the const statement, so that we can import it in the…

Contents