Inject NavCtroller in Provider


#1

When I trying to inject navCtrl in the constructor of a provider it throws some error.

ERROR Error: Uncaught (in promise): Error: StaticInjectorError(AppModule)[Content -> 
NavController]: 

StaticInjectorError(Platform: core)[Content -> NavController]:
NullInjectorError: No provider for NavController!
Error: StaticInjectorError(AppModule)[Content -> NavController]:
StaticInjectorError(Platform: core)[Content -> NavController]:
NullInjectorError: No provider for NavController!
at _NullInjector.get (vendor.js:1377)
at resolveToken (vendor.js:1675)
at tryResolveToken (vendor.js:1617)
at StaticInjector.get (vendor.js:1485)
at resolveToken (vendor.js:1675)
at tryResolveToken (vendor.js:1617)
at StaticInjector.get (vendor.js:1485)
at resolveNgModuleDep (vendor.js:11270)
at _createClass (vendor.js:11309)
at _createProviderInstance$1 (vendor.js:11281)
at _NullInjector.get (vendor.js:1377)
at resolveToken (vendor.js:1675)
at tryResolveToken (vendor.js:1617)
at StaticInjector.get (vendor.js:1485)
at resolveToken (vendor.js:1675)
at tryResolveToken (vendor.js:1617)
at StaticInjector.get (vendor.js:1485)
at resolveNgModuleDep (vendor.js:11270)
at _createClass (vendor.js:11309)
at _createProviderInstance$1 (vendor.js:11281)
at c (polyfills.js:3)
at Object.reject (polyfills.js:3)
at NavControllerBase._fireError (vendor.js:55104)
at NavControllerBase._failed (vendor.js:55097)
at vendor.js:55144
at t.invoke (polyfills.js:3)
at Object.onInvoke (vendor.js:5134)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3

But if I make ‘navCtrl’ explicitly it runs perfectly. Why I can’t inject navCtrl into the constructor of a Provider.?

can someone explain it…?


#2

You probably means services.

You need to see the lifecycle of a component and a lifecycle of a service.
You better use the navCtrl is a component.