@sunnyj58 wrote:
I’m having some difficulty getting some data to be shown the first time a page is loaded on an ionic app. What I want to happen is for a user to click a link of the menu, the page to load and data to instantly be displayed. But whats happening is nothing is shown the first time the page is loaded, but if you re-click the link from menu data will be displayed.
My code is -
export class ViewSessions { lastScans = []; ionViewWillEnter(){ this.barcodeTracker.lastScans = this.barcodeTracker.getScans(); } constructor(private barcodeScanner: BarcodeScanner, private nativeStorage: NativeStorage, private barcodeTracker: BarcodeTracker, private storage: Storage) { this.lastScans = this.barcodeTracker.getScans(); } }
The getScans function being called is -
public getScans(){ console.log(this.data); return this.data; }
I think what is happening is the array is only being created the first time the page is loaded. Then populated the second time its loaded. So I tried to create the array on the home-page which is loaded with the app, then adding data to this array when this page is loaded and showing the array from home-page in the html, but this was unsuccessful.
I tried using an ionViewDidLoad and an ionViewWillLoad, but both was unsuccessful too. How can this be resolved?
Posts: 1
Participants: 1