0

I'm subscribing to an API call using the following code:

this.af.database.list("URL")
    .subscribe((lineList) => {
      this.lineList = lineList;
      this.fullLineList = lineList;
});

Whenever I access this.lineList in my component, this.fullLineList changes too.

How I can store a variable which stores lineList and is note affected by this.lineList changes?

TheUnreal
  • 23,434
  • 46
  • 157
  • 277

1 Answers1

0

With slice() you can create a copy of the list:

this.af.database.list("URL")
.subscribe((lineList) => {
      this.lineList = lineList;
      this.fullLineList = lineList.slice();
});

See also https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/slice

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567