2017-01-23 81 views
0

我是新的離子框架。從那時起,我嘗試使用http.get檢索漫畫信息,我沒有成功Ionic 2 http undifined

這裏是我的代碼:

//mon code dans le service d'authentification 
getInfos() { 
     return new Promise(resolve => { 
      var headers = new Headers(); 
      this.loadUserInfos(); 
      console.log(this.AuthToken); 
      headers.append('Authorization', 'Bearer ' +this.AuthToken); 
      this.http.get('http://localhost/helloworld/authenticate/user', {headers: headers}).map(res => res.json()).subscribe(data => { 
       this.data = data; 
       resolve(this.data); 
      }); 
     }) 
    } 


    //mon code dans la page home 
    public viuser: any; 

    constructor(public navCtrl: NavController, public alertCtrl: AlertController, public viauth: ViAuth) { 
    this.loadinfo(); 
    } 

    loadinfo() { 
    this.viauth.getInfos() 
     .then(data => { 
     this.viuser = data; 
    }); 
    } 

回答

0

你不顯示整個代碼,但要確保你進口HTTP模塊是這樣的:

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

並將它注入到你的構造器:

constructor(public navCtrl: NavController, public alertCtrl: AlertController, public viauth: ViAuth, private http: Http) { 
    this.loadinfo(); 
}