I am changing the value for one Input directive to my child component from parent component inside subscribe block. However, the new values are not detected in the child.
The child component already implements OnChanges
and correctly defines Input directives.
Below is the pseudo code for my components. It is simplified from actual code for ease of understanding the context.
PARENT COMPONENT HTML:
<h1>PARENT</h1>
<button (click)="buttonClicked()">NEXT</button>
<child-component [inputChildVar]="parentValue"></child-component>
PARENT COMPONENT TS:
ngOnInit() {
this.parentValue= {
"currentPageNo":5,
"currentPageData": [{"DEVICE":"Kernel1","RANGE":"500Hz"}, {"DEVICE":"Kernel2","RANGE":"500Hz"}]
}
}
buttonClicked()
{
this.parentService.ServiceMethod().subscribe(data=>{
this.parentValue= {
"currentPageNo":data.currentPageNo,
"currentPageData":data.array
}
this.parentValue=JSON.parse(JSON.stringify(this.parentValue))
})
}
CHILD COMPONENT HTML:
<h1>inputChildVar<h1>
CHILD COMPONENT TS:
import { Component, OnInit, Input,OnChanges } from '@angular/core';
@Component({
selector: 'child-component',
template: '<h1>inputChildVar<h1>',
})
export class ChildComponent implements OnInit,OnChanges
{
@Input() inputChildVar
constructor() { }
ngOnChanges(){
console.log(this.inputChildVar)
}
ngOnInit() {}
}
Expected Result: On getting a response from parentService.ServiceMethod, when parentValue is changed, the new values should be reflected on screen through child component.
Actual Result: There is no change on the screen
inputChildVar
– Ankita S Jan 17 '19 at 10:05', }) export class ChildComponent implements OnInit,OnChanges { @Input() inputChildVar constructor() { } ngOnChanges(){ console.log(this.inputChildVar) } ngOnInit() {} }