nativescript-angular icon indicating copy to clipboard operation
nativescript-angular copied to clipboard

How to persist data when navigating from one page to another angular2 nativescript

Open sarvagayatri opened this issue 10 years ago • 7 comments

sarvagayatri avatar Sep 16 '16 11:09 sarvagayatri

Hi @sarvagayatri, Thank you for your interest in NativeScript.

In NativeScript Angular project you could use RouterConfig object which maps paths to components and you could past parameters while navigating as it is described in our documentation. For further help you could review the Angular2 documentation, where you could find further info about the Angular router and, how you could parse data.

You could review this thread in SO here, where this scenario has been described.

You could also use our StackOverflow and Slack canals for your questions. I hope this helps. @tsonevn

tsonevn avatar Sep 16 '16 12:09 tsonevn

I want to save few variable values through out the app, so that i can refer them in any page of app. so routing variables does't work for me. i want to persist few application state variables eg. userId, userStatus etc..

sarvagayatri avatar Sep 16 '16 12:09 sarvagayatri

Maybe this ? https://docs.nativescript.org/api-reference/modules/application_settings.html

AzSiAz avatar Sep 16 '16 14:09 AzSiAz

Hi @sarvagayatri,

You could use Application Settings as @AzSiAz has suggested, you could find an example how to use this module here in the documentation. You could also review the SO thread here, where has been described how to define global variables in Angular2.

tsonevn avatar Sep 16 '16 14:09 tsonevn

In addition to what people have already brought up, the Angular router allows you to provide parameters for the component you are navigating to:

https://angular.io/docs/ts/latest/guide/router.html#!#route-parameters

hdeshev avatar Sep 21 '16 09:09 hdeshev

What about back navigation params?

mid787 avatar Apr 02 '18 19:04 mid787

@sarvagayatri

you can use service in that case, routing will not fit. try like this.

PersistDataClass.ts class PersistDataClass { userData: Array<object> } Component where you want to set and later get. import { PersistDataClass } from './PersistDataClass'; import { OnInit } from '@angular/core'; export class UserComponent implements OnInit() { constructor(private _userservice: PersistDataClass) { } ngOnInit() { service.getUserList().subscribe( res => { _userservice.userData = res; }) } }

tameshnirmalkar avatar Oct 17 '18 01:10 tameshnirmalkar