There is a way to decide what to inject for/into a construct at runtime. So far, we have been very explicit about when to override, but we can do this with a bit of logic added to it by using the useFactory keyword. It works like the following:
let factory = () => { if(condition) { return new FakeService(); } else { return new Service(); }}@Component({ providers : [ { provide : Service, useFactory : factory } ]})
This factory can in itself have dependencies; we specify those dependencies with the deps keyword like so:
let factory = (auth:AuthService, logger: Logger) => { if(condition) { return new FakeService(); } else { return new Service(); } }@Component({ providers : [ { provide : Service, useFactory : factory,