Tôi có một dịch vụ nhập khẩu Http, và khi tôi sử dụng nó trong ứng dụng của tôi nó ném lỗi. "Không có nhà cung cấp nào cho Http! Lỗi tại g injectionError". Tôi đang lười biếng ứng dụng. Ngoài ra các nhà cung cấp đã được tạo ra thông qua cli "ionic g provider ...
"Góc 4 và Ionic 3 Không có nhà cung cấp cho HTTP
khiếu 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();
}
}
khiếu 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 {
}
Bất kỳ lời đề nghị?
Bạn phải đăng ký 'Http' đến' providers' trong mô-đun – devqon
@devqon của bạn - chúng ta cần nó trong khi lười biếng tải cũng thế? – abhiklpm
Lưu ý sự khác biệt giữa ** 'Http' ** từ Angular đến **' HTTP' ** từ các plugin gốc của Ionic. Trong trường hợp nhận được một 'không có nhà cung cấp lỗi' cho sau này, bao gồm' HTTP' - _which có thể được nhập khẩu từ 'ionic-native'_ - vào' app.module.ts' của bạn. –