How to console an observable data in container component

197 Views Asked by At

In my component I am getting data from store, like this:

ngOnInit() {

        this.appUserName = this.store.pipe(select(subscribe.getAppUserName));
        this.store.dispatch(new actions.LoadTranslationIds());
        this.data = this.store.pipe(select(subscribe.getTranslationIds));

    }

after assigned I am trying to print the "this.data" in 'ngChanges' like:

ngOnChanges() {
     console.log('trans id', this.data);
}

But ngOnChanges itself not triggering. I am not able to console the data what i receives. what is wrong with my code? or what would be the correct approach?

I am not using "subscribe" approach here.

2

There are 2 best solutions below

1
On

ngOnChanges only be called when any data-bound property of a directive changes.

Why don't you subscribe it.

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

0
On

Try like this:

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

it will work for you!