Search code examples
nativescriptnativescript-angular

this.router.back() With parameter in Nativescript


Using Nativescript 5.0 + Angular

Unable to figure out how can I accomplish it?

  1. From first view (referred in this post as original view), user taps a button

  2. this.router.navigate(["secure/booking/city"]) displays new view having listview

  3. User taps the city item he want to select from the view

  4. this.router.back() is called onItemTap

  5. User can see the original screen

I want city item details (name & ID) back to the original view.

I have tried using ApplicationSettings from second view and read back in original view, but not happening.

Below is the code snip

 this.router.navigate(["secure/booking/city"]).then((response) => {
                console.log("ret data name : " + ApplicationSettings.getString("cityname"));    
                ApplicationSettings.setString("cityname","");
            }, (e) => {
                console.log("error -ret data name : " + ApplicationSettings.getString("cityname"));   
            });

Solution

  • You could simply use a Service with BehaviorSubject, subscribe to it in the original view and update the BehaviorSubject as needed.