0

hello currently I am trying to populate a default model for originalModel to store the original values. the issue i'm running into is this originalModel keeps updating even after I initialized it and i have no idea why here is the only time I initialize value.

export abstract class RequestBaseComponent{  
    protected abstract get model(): FaspRequest; //the subClass populates this via Input()
    originalModel: FaspRequest;

    constructor(    private formBuilder: FormBuilder 
    ) {
    }

    ngOnInit() {
     this.originalModel = this.model;
     this.setupForm();
    }
}
georgeawg
  • 48,608
  • 13
  • 72
  • 95
keil
  • 39
  • 7

1 Answers1

1

Maybe this is a reference issue. When you do this.originalModel = this.model; , you are actually storing the reference of this.model in this.originalModel. So when this.model is updated, this.orginalModel will be updated.

try this

this.originalModel = JSON.parse(JSON.stringify(this.model));