1

Q) How do I pass my param to the next page as a copy, so that changes to it don't persist in the previous screen when I go back?

e.g.

  showDetails(item) {
    this._nav.push(PersonDetailsPage, {
      person: item
    });    
  }

So when I view the PersonDetailsPage, I want to be able to make changes, cancel, go back and not have the original object modified.

Thanks.

Dave
  • 5,283
  • 7
  • 44
  • 66

3 Answers3

5

Use "Object.assign"

let original = { person: items };
let copy = Object.assign({}, original );
Nejc Lepen
  • 357
  • 3
  • 5
4

For now I've gone with:

var copy = JSON.parse(JSON.stringify(obj));
Dave
  • 5,283
  • 7
  • 44
  • 66
1

In Javascript, objects are passed by reference. Only primatives (number, string, boolean, etc) are passed by value. Your best bet is going to be using the Object.assign method to make a copy of the object.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

Dan Bucholtz
  • 713
  • 1
  • 5
  • 11