I use angular-cli environment variables in the module. When I import my module into another project, is it possible to use project environment variables at compilation and runtime?
My module
myModule/ src/ /app my.service.ts /environments environment.prod.ts environment.ts app.module.ts etc.
My module my.service.ts
import { environment } from './environments/environment'; @Injectable() export class MyService { private title = environment.title; showTitle(): string { return this.title; } etc. }
My environment.ts module
export const environment = { production: false, title: 'My Module in dev mode' }
My module environment.prod.ts
export const environment = { production: true, title: 'My Module in prod mode' }
My project
myProject/ src/ /app app.component.ts /environments environment.prod.ts environment.ts app.module.ts etc.
My AppComponent Project
Component({ selector: 'app-root', template: `<h1>{{title}}</h1>` }) export class AppComponent { title: string; constructor(myService: MyService) { this.title = myService.showTitle(); } }
My project environment.ts
export const environment = { production: false, title: 'My Project in dev mode' }
My project environment.prod.ts
export const environment = { production: true, title: 'My Project in prod mode' }
Currently, when I run my project, I see My Module in dev mode, but I want to see My Project in dev mode.
Is there a way to import environment.ts
from a relative url like import { environment } from '/src/my-app/environments/environment
'?