Matt
Matt

Reputation: 1432

Is there a way to chain @Injectable() in Angular4

I'm building an Ionic 3 app (uses Angular 4). I've created a LocationProvider that will allow me to extract location services from the actual page logic so that it's reusable.

My LocationProvider uses the @ionic-native/geolocation (the Geolocation provider).

When I inject my LocationProvider into a page via @NgModule({ providers: [LocationProvider] }), I get an error saying Geolocation provider cannot be found. Is there any way to include the Geolocation provider whenever the LocationProvider is used? Or do I need to always have providers:[LocationProvider, Geolocation]?

I'm guessing this is not Ionic specific (but Angular 4), is there any way around needing to list both providers in NgModule?

Upvotes: 3

Views: 99

Answers (1)

Estus Flask
Estus Flask

Reputation: 223084

providers accepts both single providers and provider arrays.

it can be

export const LOCATION_PROVIDERS = [LocationProvider, Geolocation];
...
providers: [LOCATION_PROVIDERS]
...

Providers can also be wrapped with their own module and imported.

Upvotes: 1

Related Questions