我有一个导入Http的服务,当我在我的应用程序中使用它时会抛出错误。 “没有提供Http!g injectionError时出错”。我懒得加载应用程序。提供者也是通过cli“离子g提供者……”生成的。
投诉service.ts
import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; @Injectable() export class ComplaintService { private complaints: {subject: string,description: string}[] = []; constructor(public http: Http) { this.http = http; this.complaints = null; console.log('Hello ComplaintService Provider'); } addComplaints(complaint: {subject: string,description: string}) { this.complaints.push(complaint); } getComplaints() { return this.complaints.slice(); } }
投诉form.ts
import { Component } from '@angular/core'; import {Validators,FormBuilder,FormGroup } from '@angular/forms'; import { IonicPage,NavController,NavParams } from 'ionic-angular'; import {ComplaintService} from '../../providers/complaint-service'; @IonicPage() @Component({ selector: 'page-complaint-form',templateUrl: 'complaint-form.html',providers: [ComplaintService] }) export class ComplaintForm { }
有什么建议么?
您必须将HttpModule注册到您的模块(/app.module.ts):
import { HttpModule} from '@angular/http'; @NgModule({ imports: [ HttpModule ],declarations: [ AppComponent ],bootstrap: [ AppComponent ] }) export class AppModule { }