作者:kingseao | 来源:互联网 | 2023-02-05 17:19
我有一个导入Http的服务,当我在我的应用程序中使用它时会抛出错误." 没有Http的提供者!g injectionError时出错 ".我懒得加载应用程序.提供者也是通过cli" ionic g provider ...
" 生成的
投诉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 {
}
有什么建议?
1> devqon..:
您必须注册HttpModule
到您的模块(/app.module.ts
):
import { HttpModule} from '@angular/http';
@NgModule({
imports: [
HttpModule
],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {
}
在定义了app模块类的ts文件中