angular - 如何从父组件刷新我的数据?
问题描述
嗨,我想从父组件刷新我的时间戳值。
我的 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 在时间戳更改时没有捕捉到。
解决方案
推荐阅读
- android - Flutter - 来自firebase的readData()导致该方法被调用为null
- latex - 如何在 Rmarkdown beamer 演示文稿中拥有多个笔记页面
- java - 我如何能够确定一个字符串是否只包含一个数字?
- python - updating a label value on the GUI which gets updated value from temperature sensor all the time
- xml - visual studio intellisense: xml comment contains invalid xml: a name contained an invalid character
- azure - Where can I find published API documentation for Azure DevOps?
- javascript - animate.css 循环 2 个不同的动画
- python - Ansible:将值从一个字典替换到另一个字典而不添加整个字典
- macos - Can I detect when my webcam is used by a program on Mac OS?
- excel - How do I replace column of numbers in excel with their "th" and "nd" ending?