question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use of Environment variables in Angular 6 Library

See original GitHub issue

Type of Issue

I have a angular lib where i am using environment variables configured inside the environment.ts file which is reside inside the lib. when i am using the library in another angular 6 application how can i use those configuration variables present inside the environment.ts file for the library.

Those configuration variables inside the library environment.ts file are mostly clientID and tenantID which are being used for authentication and authorization which may change for different environment .

image

[ ] Bug Report
[ ] Feature Request

Description

A bug: please describe the error that you encountered

A feature: please describe your use case and motivation

How To Reproduce

A bug: please include instructions how to reproduce. Issues without reproduction are likely to receive no feedback.

Can you reproduce the error in the integration tests in ng-packagr? If possible, take a look at the integration/samples and try to break one of these builds!

Is the error you faced in an application importing the library Try to break the Angular CLI app in integration/consumers/ng-cli!

Expected Behaviour

A bug: please describe what behaviour or result you expected

A feature: do you have a first draft or an idea how to implement?

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: x.y.z
@angular/*: x.y.z
typescript: x.y.z
rxjs: x.y.z
node: x.y.z
npm/yarn: x.y.z

Please include all version numbers that might be relevant, e.g. third-party libraries

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
alan-agius4commented, May 9, 2019

IMO, you should not have such configuration inside the library but rather these should be provide to the library via a forRoot() method from the application.

From an ng-packagr perspective, there is no such as a dev/production build. There is only a single type of build.

I suggest you do follow the forRoot pattern ex;

myLibraryModule.forRoot({
    clientId: 1,
    tenantId: 2
});

1reaction
jsdevtomcommented, Sep 3, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing environment variables to angular library
Some of the angular services are using environment variables in our current applications (api endpoints are changed on each env). I was wondering...
Read more >
Environment sharing across libraries with Angular Injection ...
Hi there! Let's look at how you — as we do at ShopStyle — can use Angular injection tokens to share your application-specific...
Read more >
Working with Environment Variables in Angular 6 - Coding Latte
Angular provides environment configurations to declare variables unique for each environment. Ideally, you want to automatically apply a flag, ...
Read more >
How To Use Environment Variables in Angular - DigitalOcean
Learn how to set environment variables in your Angular 2+ apps and how to add new environments using the Angular CLI.
Read more >
How to inject environment variables into your Angular ...
Get all the environment variables through process.env . · Retrieve the desired environment keys in a secure way using our own secureEnvBeforePassingToAngular ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found