Good code management


I don’t want to send requests every time I go to page I want it to load once when app starts,
at this time I’m checking if listview data is null and after this send request to server if I dont have data in listview, so it helps me to send request once.
but my problem is when logout from user 1 and then login with user 2
user 1 data is showing.
so I need to clear all the data of all pages when logout, but I cant figure it out how to do this.
I have more pages then one and I cant clear (set it to null) main page data for example if I’m doing logout from contacts page.

I’m on nativescript core, I’m using data binding, mvvm structure.


You may fire a custom event upon logout, clear everything on the callback function.


can you create an example in playground please?


I have no idea how you navigate between pages / where you load data. So if you create an example application, I can help you with right solution.

If you are just looking for examples to create custom events, it’s documented here.


ok I will create an example app



here is dummy app


I have updated your example.

In general few things to keep in mind (may be your requirements are different, I’m not sure).

  1. Usually when we already have the page’s instance available in back stack, we navigate back and don’t create new instance over and over.
  2. Most applications will clear history and take user back to login / home page when he logs out by which you don’t have to worry about cleaning up data of pages in back stack.

CustomEvent Usage