dependency injection - angular 4 ngModule inject provider/services conditionally -
in app.module.ts
@ngmodule({ ... providers: [myservice, // providers used create fake backend fakebackendprovider, mockbackend, baserequestoptions ], bootstrap: [appcomponent] })
fakebackendprovider, mockbackend , baserequestoptions mock end. there way inject these services variable in environment.ts file?
you can use this. created plunker
//route environment file import { environment } '../../environments/environment'; providers: [myservice, // providers used create fake backend { provide: someserivce, usefactory: authheadersfactory }, ], export function authheadersfactory() { if (environment.prod) { return new mock(); } return new fakebackend(); }
Comments
Post a Comment