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();
}
This may be occuring because of the lifecycle timings. You are firing a log on the constructor, what if you ran it on ngOnInit() or at a later lifecycle hook?
the function initializeItems() defined by you as above is working in asynchronously, so before getting getEmpresas() response, the next line of your code also executed along with it.
So define your function with async and await, to call it synchronously.