Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Dependency Injection in @Page annotations

$
0
0

I am attempting to inject Http from Angular2/Http into a Page element, and am not seeing a direct way to do this.

I browsed through the source for the Page element and noticed it does not accept a providers array like it would for @Component or @App. It also appears that the bootstrap is being done well away from the @App component where I would expect it, which is limiting my ability to inject as well.

I have attempted to inject in @App via:

@App({
templateUrl: 'app/app.html',
providers: [HTTP_PROVIDERS]
})

and attepted to call in in my GettingStarted page via:
export class GettingStartedPage {
constructor(nav: NavController, @Inject(Http)http: Http) {

This yields the following error:

EXCEPTION: Cannot resolve all parameters for GettingStartedPage(NavController, @Inject(undefined)). Make sure they all have valid type or annotations.

Considering that the @App annotation signifies the root component of the application, the Http service should have been availible in the component. I have confirmed that the injection on the application annotation does provide injection in the application class.

I also attempted to utilize both an @Page and @Component, but this breaks some of the ionic component selectors for some reason.

Is there another way in which I should be able to inject the Http provider into a component with an @Page annotation, or a more appropriate way to handle this?


Viewing all articles
Browse latest Browse all 228595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>