I am new in ionic and angular. I want to get data from API but I can't access the data.
Here is my code
public items: any;
constructor(
public navCtrl: NavController,
public modalCtrl: ModalController,
public navParams: NavParams,
public http: Http) {
let headersToken = new Headers();
headersToken.append('Authorization', 'Bearer token here');
this.http.get('http://localhost:8000/api/data',{headers : headersToken}).map(res => res.json()).subscribe(data => {
this.items = data;
});
}
ionViewDidLoad(){
console.log(this.items);
}
And the result of IonViewDidLoad
is undefined.