1

在我的组件中,我从商店获取数据,如下所示:

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本身没有触发。我无法控制我收到的数据。我的代码有什么问题?或者什么是正确的方法?

我在这里没有使用“订阅”方法。

4

2 回答 2

1

试试这样:

this.data = this.store.pipe(select(subscribe.getTranslationIds)).pipe(tap((val) => console.log(val)));

它会为你工作!

于 2019-10-16T09:44:47.317 回答
0

ngOnChanges仅在指令的任何数据绑定属性更改时调用。

你为什么不订阅它。

https://angular.io/api/core/OnChanges

于 2019-10-16T08:43:47.870 回答