2017-04-25 18 views
21

के लिए कोई प्रदाता नहीं है मेरे पास एक सेवा है जो एचटीपी आयात करती है, और जब मैं इसे अपने ऐप में उपयोग करता हूं तो यह त्रुटि फेंकता है। "एचटीपी के लिए कोई प्रदाता नहीं! जी इंजेक्शन त्रुटि में त्रुटि"। मैं ऐप को आलसी लोड कर रहा हूं। इसके अलावा प्रदाता CLI के माध्यम से "ionic g provider ..."कोणीय 4 और आयनिक 3 HTTP

शिकायत-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

आप रजिस्टर करने के लिए है 'Http' अपने मॉड्यूल – devqon

+0

@devqon में' providers' करने के लिए - हम इसे जबकि आलसी लोड हो रहा है की क्या ज़रूरत है भी? – abhiklpm

+0

आईओनिक के मूल प्लगइन से कोणीय से ** 'HTTP' ** के बीच **' Http' ** के बीच का अंतर नोट करें। उत्तरार्द्ध के लिए 'कोई प्रदाता त्रुटि' प्राप्त करने के मामले में, 'HTTP' - _ जिसे 'ionic-native'_ से आयात किया जा सकता है - को आपके 'app.module.ts' में शामिल किया जा सकता है। –

उत्तर

59

आप अपने मॉड्यूल (/app.module.ts) को HttpModule रजिस्टर करने के लिए है:

import { HttpModule} from '@angular/http'; 

@NgModule({ 
    imports: [ 
    HttpModule 
    ], 
    declarations: [ AppComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { 
} 
+0

मुझे यह कोड कहां लिखना चाहिए? – malhobayyeb

+3

टीएस फ़ाइल में जहां आपकी ऐप मॉड्यूल क्लास को – devqon

+0

परिभाषित किया गया है, मैं इस प्रोजेक्ट में अपनी प्रोजेक्ट में यह जोड़ता हूं: 'testIonic/src/app/app.module.ts' और यह काम करता है :) –

संबंधित मुद्दे