angular - Using @ngrx/store in Angular2 -
i working on sample application using angular 2 , @ngrx/store(for state management)
when execute below code not getting error , expected output not displayed.
// employeestate.ts export interface employee { id: number; name: string; isactive: boolean; }
// feature module es.module.ts
import { ngmodule } '@angular/core'; import { routermodule } '@angular/router'; import { storemodule } '@ngrx/store'; import { commonmodule } '@angular/common'; import { employeecomponent } './employee.component'; import { employee } './employeestate'; import { empreducer } './employeereducer'; @ngmodule({ imports:[ routermodule.forchild([ {path:'emp' , component: employeecomponent} ]), storemodule.providestore([{employee: empreducer}]), commonmodule ], exports:[], providers:[], declarations:[employeecomponent] }) export class esmodule { }
employeereducer.ts
import { action , actionreducer } '@ngrx/store'; import { employee } './employeestate'; var emp: employee = { id: 1 , name: 'testname' , isactive: true }; export const empreducer : actionreducer<employee> = ( state: employee = emp , action: action) => { return state; }
employee.component.ts
import { component , changedetectionstrategy} '@angular/core'; import { store } '@ngrx/store'; import { observable } 'rxjs/observable'; import { employee } './employeestate'; interface appstate { employee: employee; } @component({ selector:'', template: ` <h2> employee name is: {{emp$.name | async}}</h2> ` }) export class employeecomponent { emp$: observable<employee>; constructor(private store: store<appstate>) { this.emp$ = this.store.select<employee>('employee'); } }
when employeecomponent gets displayed expecting output "employee name is: testname" instead "employee name is:" . idea issue in code.
Comments
Post a Comment