I have a .ts class with a variable decorated as @Input
I would like to make a copy of this object but i cant figure out the right place to do this is, my current code:
@Input() myObj: MyObj;
public copy: MyObj;
ngOnInit() {
this.copy = JSON.parse(JSON.stringify(myObj));
}
The call within the ngOnInit method breaks because the ngOnInit is called before the myObj variable is fully created.
I have also tried to create the copy within the ngAfterContentInit method but that is also called before myObj variable is fully created.
I have seen other questions similar to mine, but they all wait for an observable, my object is not an observable, is simply an object passed from parent to child through the view:
<child-view [myObj]="myObjInParent"/>