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();
    }
}

1 Answer 1

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));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.