Search code examples
angularngrx-storengrx-effects

How can I get an object from ngrx-store


How can I get an object from ngrx-store?

I'm trying to do this

<div class="container">
      <h1>
          {{category$.name}}
      </h1>
</div>

Component

export class CatalogViewController {
private routeSubscription: Subscription;
private uri: string;

category$: Observable<any>;

constructor(
    private store: Store<fromRoot.State>,
    private route: ActivatedRoute,
    private router: Router,
    private titleService: Title
) {
    this.routeSubscription = route.params.subscribe(params=>this.uri = params['uri']);
    this.store.dispatch(new catalogActions.LoadCategory({"uri": this.uri}));

    this.category$ = store.select(fromRoot.getCategory);
   }
}

Data in the store is available

Store

catalog: {
    category: {
      name: 'Phones',
      uri: 'phones',
      __typename: 'Category'
    }
}

A simple situation, but I can not understand what I'm doing wrong :D


Solution

  • just do

    <div class="container">
          <h1>
              {{(category$ | async)?.name}}
          </h1>
    </div>