No puedo entender por qué no asigna el valor a la variable this.userProfile
probé con promesas y tampoco asigna, alguna idea?
Código:
import { Component, OnInit } from '@angular/core';
import { NavController, NavParams, LoadingController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import * as localforage from "localforage";
import { ProfileServices } from '../../providers/profile.services';
@Component({
selector: 'page-profile',
templateUrl: 'profile.html',
providers: [ProfileServices]
})
export class Profile {
public user: any;
public userProfile: any;
constructor(public navCtrl: NavController, private profile: ProfileServices, public params: NavParams, public storage: Storage, public loading: LoadingController) {
this.getPerfilData();
console.log("user profile" + this.userProfile); //Undefined ?
}
getPerfilData() {
this.presentLoadingDefault();
this.storage.get('user').then((user) => {
this.user = JSON.parse(user);
this.profile.getProfile("token", this.user.idUser).subscribe(
(data) => {
this.userProfile = data;
console.log("user profile" + this.userProfile); //Aqui me retorna la Data http success
});
});
}
presentLoadingDefault() {
let loading = this.loading.create({
content: 'Please wait...'
});
loading.present();
setTimeout(() => {
loading.dismiss();
}, 2000);
}
ionViewDidLoad() {
// this.getPerfilData();
}
ionViewWillEnter() {
// this.getPerfilData();
}
}
Gist: https://gist.github.com/vanckruz/92d6ea6ac114e6d28e88eb22caddc82a
data
?(data) =>
pordata =>