Angular 如何显示减速器的当前状态?
试着了解angular 2的ngrx/store api。我实现了一个简单的计数器减速机:Angular 如何显示减速器的当前状态?,angular,ngrx,Angular,Ngrx,试着了解angular 2的ngrx/store api。我实现了一个简单的计数器减速机: import {Store} from '@ngrx/store' export const INCREMENT ='INCREMENT'; export const DECREMENT='DECREMENT'; export const counter = (state = 0, {type, payload}) => { switch(type){ case INCREMENT
import {Store} from '@ngrx/store'
export const INCREMENT ='INCREMENT';
export const DECREMENT='DECREMENT';
export const counter = (state = 0, {type, payload}) => {
switch(type){
case INCREMENT:
return state=state+1;
case DECREMENT:
return state=state-1;
default:
return state;
}
}
我想显示计数器值:
@Component({
selector: 'todo-app',
providers: [],
template: `
<div>
<nextStepButton (next)="prev()"></nextStepButton>
<nextStepButton (next)="next()"></nextStepButton>
how to display the counter:{{counter.val}}
<log-monitor></log-monitor>
`,
directives: [LogMonitor, myList, step, nextStepButton, step2],
changeDetection: ChangeDetectionStrategy.OnPush
})
@组件({
选择器:“todo应用程序”,
提供者:[],
模板:`
如何显示计数器:{{counter.val}
`,
指令:[日志监视器,myList,步骤,下一步按钮,步骤2],
changeDetection:ChangeDetectionStrategy.OnPush
})
如何在模板中显示计数器值
githublink:我在这里找到了答案:。您必须将减速器声明为可观察对象。我在这里找到了答案:。你必须声明减速器是可观测的