0
用户试图帮助处理关于该帖子的问题:My stackoverflow old post我现在试图使用Ngrx store github来实现Ngrx商店,以帮助我解决多个输入/输出事件。在将Ngrx商店服务实施到我的组件中的问题
只是我的构造后,我有一个错误:
counter
is not assignable to parameter of type(state: Appstate) => boolean
:
child.ts:
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { UserService3 } from '../user3.service';
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { ON, OFF, RESET } from '../counter';
interface AppState {
counter: boolean;
}
@Component({
selector: 'my-daydetail',
templateUrl: './my-daydetail.component.html',
styleUrls: ['./my-daydetail.component.css']
})
export class MyDaydetailComponent {
counter: Observable<boolean>;
constructor(private store: Store<AppState>) {
this.counter = store.select('counter');
}
//...
}
counter.ts
import { Action } from '@ngrx/store';
export const ON = 'ON';
export const OFF = 'OFF';
export const RESET = 'RESET';
export function counterReducer(state: boolean = true, action: Action) {
switch (action.type) {
case ON:
return false;
case OFF:
return true;
case RESET:
return 0;
default:
return state;
}
}
@PierreDuc也许应该使用'功能'而不是? –
你做错了权利递增递减可用于布尔类型右 –
@RahulSingh认为我gotcha看看我的更新后的帖子,按照你的指示,我想我实现了正确的:-),现在nGrx如何帮助我从我的问题旧帖子? –