I have parent component which emittes latest value and in child component it uses @Input wheire in it does not return latest value.
Basically it starts like this in child component...
@Input() test;any;
We do bind this test into HTML and then on click event of button we do something with input value 'test'
onClickButton() {
this.test='your request is in progress'
....does some function where in it passes call to parent componentt and there it retrives the latest data of test so I am expecting that this.test would replaced by latest data from parent component.
}
However, this is not the case here, it retains 'your request is in progress...'
I tried in child component like ngOnChanges(changes:simpleChanges) and tried to assign currentValue to the this.test value; but things are not moving in right direction. everything process right even in parent component i tried printing latest value but in child it remains old value.
I also tried
this.ref.detectChanges();
this.ref.markforCheck();
but things are not helping me any ways to get updated value from Parent Component.
Parent.ts
this.test ="getting value from services and can see in debugger that value is coming"
@Input()only checks changes when reference of input-property is changed. If you simply changes values then reference of object is same and thus onChanges is not getting to work..this.obj = { ...this.obj }this de-structuring syntax you have changed values and reference too.. now onChanges() is get to be fired.. - GaurangDhorda