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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -