0
votes

I'm using Nativescript 6 with Angular 8 and I have an issue with the data binded values.

I have two pages. From the first page, I load the values with queryParams:

private getParamData: any;

public ngOnInit() {
    this.route.queryParams.subscribe((params) =>  {
        this.getParamData = <any> JSON.parse(params["DataList"]);
    }); 
}

When I move to the second page to return to the first one, the data are first correctly binded and then they are undefined, few seconds later.

How could I preserve the getParamData?

EDIT

Below a link to the Playground for a better understanding: https://play.nativescript.org/?template=play-ng&id=a8XYdf&v=19

When you tap on the Home Label then on the Second Label and finally go back, the Second Label becomes the Third

1
It's true that queryParams may not be retained on back navigation. You will have to take a snapshot of query params in a local variable and bind the local variable. - Manoj
That's what I did with getParamData which is a local component variable. - phenric
I suspect it to act as a pointer or something like that. So when queryParams disappears getParamData is undefined - phenric
I don't think so, can you share a Playground Sample where the issue can be reproduce. - Manoj
Use this.value = this.route.snapshot.queryParams.yourQueryParamName; and bind value in template. - Manoj

1 Answers

1
votes

Preserve the value of query param in a local variable.

this.value = this.route.snapshot.queryParams.yourQueryParamName