@carvear wrote:
Hello, i am trying to implement searchbar with values from Json. When i try to print empresas.lenght it is 0 but I have values in the json, i’ve checked it.
If I print values inside the function getEmpresas it shows the correct value.The value losts outside the function.
Thanks a lot!
empresas: any;
constructor(public navCtrl: NavController, public navParams: NavParams, public http: Http) {
this.initializeItems();
}initializeItems() {
this.getEmpresas();
console.log(“aa”+this.empresas.length); // Print 0
}getEmpresas(){
this.empresas = ;
this.http.get(“http://www.xxxxxxxxxxxx.com/empresas.php”).subscribe( data => {
this.empresas = JSON.parse(data["_body"]);
console.log(“aa”+this.empresas.length); // Prints 1 correctly
}, err =>{
console.log(err);
});
}
Posts: 3
Participants: 2