我想知道保税财产何时收到一个值,即使它是相同的值。
例如
那是一个特征组件
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.');
}
}
应用程序的组件
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
);
}
}
最后,应用程序的模板
<feature-component
[bondedProperty]="bondedProperty"
>
</feature-component>
bondedProperty
ngOnChanges
问题是,如果没有调用相同的值,并且该ngDoCheck
方法不能解决我的问题,因为我不知道“更改”是否在bondedProperty
.