Following a user's attempt to address an issue related to my post on Stackoverflow titled "My stackoverflow old post", I am currently working on implementing the Ngrx store using the guidelines provided on Ngrx store github. This will assist me in handling multiple input/output events effectively.
Upon inspecting my constructor, I encountered the following error:
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;
}
}