Quantcast
Viewing all articles
Browse latest Browse all 38

Answer by learning... for Ionic Runtime Error Cannot read property '0' of undefined

I am facing the same issue (I am learning ionic ). The only way I am able to solve it by putting the function call in both ngOnInit and ionViewWillEnter. When i declare the array then i get an error regarding "title" property.

When I remove the function call from ngOnInit i get the error: ERROR TypeError: Cannot read property '0' of undefined.

My example is very simple. I have a service which has a private array with a getter to get its content. I am not making any database calls for my example.

And here is the type script code that works for me.

  loadedPlaces: Place[];  listedLoadedPlaces: Place[]; //for virtual scroll  constructor(private placesService: PlacesService, private menuCntrl: MenuController) { }  ngOnInit() {    console.log('ngOnInIt');    this.loadData();  }  ionViewWillEnter(){    console.log('ionViewWillEnter');    this.loadData();  }  loadData(){    this.loadedPlaces = this.placesService.places; //getter property    //for the virtual scroll    this.listedLoadedPlaces = this.loadedPlaces.slice(1);  }

My environment

node: v14.15.5npm: 6.14.11angular: 11.2.0ionic: 6.13.1

Viewing all articles
Browse latest Browse all 38

Trending Articles



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