![](/img/trans.png)
[英]How can I refresh my table content from the child component in the parent component with click event?
[英]How to refresh my data from parent component?
嗨,我想從父組件刷新我的時間戳值。
我的parentComponent.ts
public updateComponent(){
this.timestamp = new Date();
this.timestamp.setDate(this.timestamp.getDate() - 30);
this.timestamp = this.timestamp.toJSON();
}
public ngOnInit() {
this.updateComponent();
interval(10000).subscribe(() => {
console.error('called');
console.error(this.timestamp);
this.updateComponent();
});
}
//my parent.component.html
<app-dashboard-card [refresh]="timestamp"></app-dashboard-card>
//When I catch my data
private ts: any;
@Input()
set refresh(timestamp: any) {
console.error("TIMESTAMP CHANGE -> ", timestamp);
this.ts = timestamp;
};
我不知道為什么時間戳更改時我的@Input無法捕獲。
在父組件中更改對象的引用時,將調用ngOnChanges()
import { Input, SimpleChanges } from "@angular/core";
ngOnChanges(changes: SimpleChanges) {
if (changes['refresh']) {
//do something after value change
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.