angular - How to get data from ngrx/store from route parameter -
how particular product details store other page while routing? i've tried achieve this, not able sort out how dispatch event store other route! see following files ref.
here product store file:
import { action, actionreducer } '@ngrx/store'; import {product} "../product.model/product.model"; export const productstore: actionreducer<product[]> = (status: product[] = [], action: action) => { switch(action.type){ case 'set_list' : status = action.payload; return status; case 'get_product' : return status; default : return status; } }
here product page i've used ngrx/store:
import { oninit, component } '@angular/core'; import {product} "../../product.model/product.model"; import {appservice} "../../app.service/app.service"; import { store } '@ngrx/store'; import { observable } 'rxjs/observable'; @component({ selector: 'product-pg', template: ` product list goes here: <ul> <li *ngfor = 'let product of $productlist | async'> {{product.name}} - <a [routerlink] = "['/product-details', product.id]">edit</a> </li> </ul> ` }) export class productpagecomponent implements oninit{ private $productlist: observable<product[]>; constructor(private _service: appservice, private _store: store<product[]>){} ngoninit(){ this.$productlist = this._store.select('productlist'); this._service.setproductlist() } }
and here wanted single product details - product details page:
import { component, oninit } '@angular/core'; import { activatedroute } '@angular/router'; import { store } '@ngrx/store'; import { observable } 'rxjs/observable'; import {product} "../../product.model/product.model"; @component({ selector: 'product-details-page', template: ` product details page goes here... {{selectedproduct$ | async}} ` }) export class productdetailspagecomponent implements oninit{ private selectedproduct$:observable<product>; constructor(private route: activatedroute, private _store :store<product>){} ngoninit(){ this.route.params.subscribe((param) => { console.log(param["id"]) //can't figure-out how achieve or store here??? this.selectedproduct$ = this._store.dispatch({type: 'get_product', payload: param["id"]}); }) } }
here i'm not able single product details store of route parameter. how achieve this, please me?
Comments
Post a Comment