Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70440

Why length equal to 0?

$
0
0

@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

Read full topic


Viewing all articles
Browse latest Browse all 70440

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>