From the course: Creating Angular Libraries

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Configuring library environments

Configuring library environments - Angular Tutorial

From the course: Creating Angular Libraries

Configuring library environments

- [Instructor] Injection tokens are the simplest way to pass environment variables into your angular library. This eliminates the need for conditional logic and makes your library more universal. I opened our project here in a GitHub code space. I talk about why we use code spaces earlier in this course. So for now, just think of them as an easy way to share and write code without installing anything on your local machine. From the root of our workspace, I'll go to source, app, and click on app.config.ts to open the file. In my work, we often use Angulars environment object to define different APIs for each build target. Angular libraries don't have environment objects the same way applications do, but they do have injection tokens, which we can use to pass data from the consuming application into the library at runtime. Let's take a look at the code. Our custom library exports a public token called API base URL, and expects consuming applications to provide this token as part of…

Contents