Using http without modifying html

Hi guys,

I can only find http requests where the http:Http object is given by ionic through a hook in the html. But ofcourse a lot of the background processes one uses don’t depend on the page that is opened. So I wondered if there is some way to get a http object without creating a hook in the html. (My best guess is that you can get it through the MyApp object, but im not sure).

Any help with this would be great.

Thanks,
Daan

I’m not sure if I’m following your question since I don’t know what you mean by…

the http:Http object is given by ionic through a hook in the html.

That said, I think you want an @Injectable service which is injected into your app.

I think this answer on SO describes it succinctly.

This is great, I didn’t know you could specify providers in the @Page and @Component tags.

For those who have the same issue:
I now give the provider to the default @component in app.ts

@Component({ template: '<ion-nav [root]="rootPage"></ion-nav>', providers: [HttpProvider] })

and receive it in the constructor of MyApp.

export class MyApp
{
	...

	constructor(private platform: Platform, httpProvider: HttpProvider)
	{
	}
}

There was still some guessing involved about whether or not it would work but it seems that it does work. So that’s great.