angular8 - 如何控制容器组件中的可观察数据
问题描述
在我的组件中,我从商店获取数据,如下所示:
ngOnInit() {
this.appUserName = this.store.pipe(select(subscribe.getAppUserName));
this.store.dispatch(new actions.LoadTranslationIds());
this.data = this.store.pipe(select(subscribe.getTranslationIds));
}
分配后,我试图在“ngChanges”中打印“this.data”,例如:
ngOnChanges() {
console.log('trans id', this.data);
}
但ngOnChanges
本身没有触发。我无法控制我收到的数据。我的代码有什么问题?或者什么是正确的方法?
我在这里没有使用“订阅”方法。
解决方案
试试这样:
this.data = this.store.pipe(select(subscribe.getTranslationIds)).pipe(tap((val) => console.log(val)));
它会为你工作!
推荐阅读
- swift - 如何更改 UIDatePicker 中文本的颜色?
- angular - 重新访问组件时,Angular 是创建单例类还是新类
- python - 如何打印与输入字符串同名的变量?
- css - 是否可以隐藏 Primeng 日历中的输入字段?
- python - 在 conda 中自动更新 requirements.yml
- regex - 带有可能前缀的 grep SHA-1 哈希
- hyperledger-fabric - 如何使用 Convector 使用 JSON 对象查询 CouchDB 富查询?
- python - 查找列表项然后获取下一个列表项
- ruby - 使用 Ruby 编辑 windows HOST 文件
- php - 如何将包含 100,000 条记录的 90MB JSON 文件解析、排序和打印到 CSV?