duke666
duke666

Reputation: 65

the state is always undefined

The subscribe is never called, yet I increment and decrement.

this.store.select('counter').subscribe(counter => {
  this.counter = counter;            
  console.log("subscribe", this.counter);
});

You can see my code on stackblitz to debug :

https://stackblitz.com/edit/angular-ivy-hntnex?file=src/app/components/comp1/my-counter/my-counter.component.ts

I don't understand, it's very strange.

Upvotes: 0

Views: 149

Answers (1)

AliF50
AliF50

Reputation: 18879

Change this line in app.module.ts:

StoreModule.forRoot({ count: counterReducer }),

to:

StoreModule.forRoot({ counter: counterReducer }),

When you're subscribing, you're looking for the counter but you had it registered as count in your AppModule.

Upvotes: 1

Related Questions