What is the best/proper way to import a service based on the current environment within an angular-cli project?
I have setup up a new environment called dev-mock which I can call with ...
ng serve --environment=mock
I then set up the provider in the module with useClass
app/app.module.ts ...
import {environment} from '../environments/environment';
import {ApiService} from './api/api.service';
import {MockApiService} from './api/mock/mock-api.service';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
FormsModule,
HttpModule
],
providers: [
{
provide: ApiService,
useClass: (environment.name === 'dev-mock') ? MockApiService : ApiService
}
],
bootstrap: [AppComponent]
})
This works fine, the problem then is what do I do when I want to inject that into another service or component, for example ...
app/ticket/ticket.service.ts
import {ApiService} from '../api/api.service'; // *** WHAT AM I TO DO HERE? ***
@Injectable()
export class TicketService {
constructor(private api: ApiService, private http: Http) {
}
}
Obviously my approach is wrong. What is the correct approach?