I’ve recently updated angular version from 12 to 13. I have a class with a clone method. The implementation of the the class is something like this:
export class MyClass {
...
public clone(): MyClass {
const newObject: MyClass = Util.deepClone(this);
newObject.updateProperty();
return newObject;
}
...
}
The deepClone
method at Util
class has the following implementation:
/**
* Returns a deep copy of the object
*/
public static deepClone(oldObj: any) {
let newObj = oldObj;
if (oldObj && typeof oldObj === 'object') {
if (oldObj instanceof Date) {
return new Date(oldObj.getTime());
}
newObj =
Object.prototype.toString.call(oldObj) === '[object Array]' ? [] : {};
for (const i in oldObj) {
newObj[i] = this.deepClone(oldObj[i]);
}
}
return newObj;
}
My problem is: this piece of code works in version 12, but it doesn’t in version 13.
The function “ùpdateProperty()“` is undefined in version 13, but it is ok in version 12.
As I couldn’t find anyone with similar issues neither similar questions, I would like some help to find:
- what changed from Angular 12 to Angular 13 that makes this piece of code stop working in version 13;
- how to solve the issue.