I have a variable in the parent component like this:
ParentComponent
export class ParentComponent {
variable = {};
varExample = false;
@ViewChild('child') child: ChildComponent;
someFunction () {
this.variable['id'] = {};
for (let i = 0; i < 10; i++) {
this.variable['id'][i] = i*2;
}
this.varExample = true;
}
otherFunction () { // called when i click a button
this.someFunction ();
console.log(this.child.variable); // {}
console.log(this.child.varExample); // true
this.child.initVars();
}
}
Parent HTML
<app-child #child [variable]="variable" [varExample]="varExample"></app-child>
ChildComponent
export class ChildComponent {
@Input() variable: any;
@Input() varExample: boolean;
initVars() {
console.log(this.variable); // {}
console.log(this.varExample); // true
}
}
This is just an example of my implementation and yes I have all imports.
In those console.log(this.variable) I got an empty object ( {} ), but varExample still works fine.
Why is child's variable always empty, Angular doesn't detect changes in this type of Objects ( {} ) ?
Can someone help me?
@Input() variable: any;to@Input() variable: {};