Ionic v2 http service provider not working


#1

I created project in ionic with blank template after that i added 2 pages and 1 provider. Provider is for calling my api from pages but provider gives some simple error but i dont know what is happening here.

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class NoteService 
{
	data: any;
	constructor(public http: Http) 
	{
		console.log('Hello NoteService Provider');
	}

	load() 
	{
	}
}

I dont know why this is happening i haven’t right code in provider that is comes from ionic generator command.

Please help me out…!


#2

You probably forgot to import the HttpModule into your app.module ?


#3

Thanks for your reply. i missed to include that. i did like

import { HttpModule } from ‘@angular/http’;

and pass in import like

imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpModule
],

Means if i have to use any module first i have to include in app.module.ts file after that in service file or other pages. but can you just tell me why we have to write it.

HttpModule i cannot right any word instead of that?


#4

Because otherwise the build system doesn’t know to include the code needed to make http requests. Apps that don’t make http requests don’t want to include that code needlessly.


#5

Ok. Thanks i thought ionic is did that automatically because i use command line for generator provider but that is need to do manually. Thanks for your quick answer.