Created
November 16, 2023 18:38
-
-
Save teomanofficial/f40c354dd18de41956e3d93868f50f52 to your computer and use it in GitHub Desktop.
Angular NGXS State Management - Products Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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