I have this component:
@Component({
selector: 'child'
})
export class ChildComponent {
@Input() childObject: ChildObject;
changeObject(newObject: ChildObject){
childObject = newObject;
}
}
When I call changeObject, my ChildComponent reflect the changes, but my ParentComponent, which contains the ChildComponent, isn't updated with this change.
I.e.: If, in my ParentComponent template I have something like {{parent.childObject.name}}, this value stay unchanged.
I tried to use childObject = JSON.parse(JSON.stringify(newObject)); but it doesn't help.
I guess it's a problem of object reference changing, so I added a method copy(newObject: ChildObject) that makes a copy property-by-property in my ChildObject class, but when I call it in my changeObject method, I get this error:
ERROR TypeError: _this.childObject.copy is not a function.
Update: ChildObject class
export class ChildObject {
constructor(
public name: string // , ...
) { }
copy(childObject: ChildObject) {
this.name = childObject.name;
// ...
}
}
@Input()properties doesn't carry the reference@inputworks the other way try@outputinstead.