I have been trying to do something similar, however, my implementation attempted to expand on the way providers were declared in a seperate providers.ts file in the new Ionic Super Starter: https://github.com/driftyco/ionic-starter-super/blob/master/src/providers/providers.ts
In my method, I tried to declare the references here once, commenting out the mock/live providers that I didn’t want to use.
e.g. providers.service.ts
import { EventService } from './event.service';
import { SettingsService } from './settings.service';
//Production
import { APIService } from './api/cms.service';
import { ProductService } from './api/product.service';
import { CartService } from './api/cart.service';
//Mocks
import { MockAPIService } from './mock/mock.service';
//import { ProductService } from './mock/product.service';
//import { CartService } from './mock/cart.service';
export {
APIService,
EventService,
ProductService,
CartService,
MockAPIService,
};
I then made reference to these services by always pointing to the providers.ts
anywhere that they where needed e.g.
//Providers
import {APIService} from '../providers/providers.service';
import {MockService} from '../providers/providers.service';
import {EventService} from '../providers/event.service';
import {ProductService} from '../providers/providers.service';
import {CartService} from '../providers/providers.service';
This worked for the most part, but just today I have run into an issue, where if one service refers to another that was also defined in providers.service.ts, the injection doesn’t seem to work properly. No TS issues, but on app run I get unresolved dependencies/injection in my JS console. For example:
Can't resolve all parameters for CartService: (Storage, Http, ?, EventService).
CartServices uses ProductService from the same providers.service file, uses it in the constructor as follows:
export class CartService {
constructor(public storage: Storage, public http: Http, public productService: ProductService, public event: EventService) {
}
Would really appreciate any explanation as to why this is the case, or how I could address it?