Skip to content

Instantly share code, notes, and snippets.

@teomanofficial
Created November 16, 2023 18:38
Show Gist options
  • Save teomanofficial/f40c354dd18de41956e3d93868f50f52 to your computer and use it in GitHub Desktop.
Save teomanofficial/f40c354dd18de41956e3d93868f50f52 to your computer and use it in GitHub Desktop.
Angular NGXS State Management - Products Component
import { Component, OnInit } from '@angular/core';
import { Select, Store } from "@ngxs/store";
import { Observable } from "rxjs";
import { ProductsState } from "@store/products/state/products.state";
import { ProductModel } from "@store/products/models/product.model";
import { GetProducts } from "@store/products/state/products.actions";
@Component({
selector: 'app-products',
templateUrl: './products.component.html',
styleUrls: ['./products.component.css']
})
export class ProductsComponent implements OnInit {
@Select(ProductsState.selectProducts)
products$: Observable<ProductModel[]>;
constructor(private readonly store: Store) {
}
ngOnInit(): void {
this.store.dispatch(new GetProducts({ skip: 0, limit: 9 }))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment