微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular 4和Ionic 3没有HTTP的提供者

我有一个导入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 {
}

原文地址:https://www.jb51.cc/angularjs/144010.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐