I would like how to know when a bonded property receives a value, even if it's the same value.
For example
That is a feature component
import {
Component,
OnInit,
Input,
OnChanges,
SimpleChanges
} from '@angular/core';
@Component({
selector: 'feature-component',
templateUrl: './template.html',
styleUrls: ['./style.sass']
})
export class FeatureComponent implements OnInit, Onchanges {
@Input() bondedProperty: any;
ngOnInit() {
}
ngOnChanges(simpleChanges: SimpleChanges) {
// not called inside the setInterval function
console.log('the bonded property received any value.');
}
}
The component of the app
import {
Component,
AfterViewInit
} from '@angular/core';
@Component({
selector: 'app-component',
templateUrl: './template.html',
styleUrls: ['./style.sass']
})
export class AppComponent implements AfterViewInit {
bondedProperty: any;
constructor() {
this.bondedProperty = 10;
}
ngAfterViewInit() {
const
interval = setInterval(
() => {
this.bondedProperty = 10;
console.log('function called after interval');
clearInterval(interval);
}, 5000
);
}
}
And finally, the template of the app
<feature-component
[bondedProperty]="bondedProperty"
>
</feature-component>
The problem is that if the same value is assigned in bondedProperty
ngOnChanges
isn't called, and the ngDoCheck
method doesn't solve my problem because I would not know if the "change" was in bondedProperty
.