I'm new with the use of ngrx on angular, when I dispatch to the Authentication action nothing happens I don't even have errors in the console can someone tell me where the error is! I think the problem in the dispatch or effects does not detect the action!
//action.ts
export const cuurentUser=createAction('currentUser',props<any>());
export const LOGIN = 'LOGIN';
export const Authentication = createAction(
LOGIN,
props<{payload: any}>()
);
///components.ts
login(){
this.store.dispatch(Authentication(this.params))
}
///effects.ts
@Injectable()
export class AuthenticationEffects{
user=createEffect(()=>this.action.pipe(
ofType(LOGIN),
map((action:typeof Authentication)=>action),
tap((payload:any)=>{
this.authService.login(payload).pipe(
map((resp)=>{
cuurentUser(payload.username)
console.log(resp)
}),
catchError(error=>of(console.log(error)) )
)
})
)
)
///module.ts
@NgModule({
declarations: [
LoginComponent
],
imports: [
CommonModule,
AuthenticationRoutingModule,
FormsModule,
StoreModule.forRoot({reducerA:AuthenticationReducer}),
EffectsModule.forRoot([AuthenticationEffects])
]
})
You done a silly mistake which is ofType(LOGIN)
instead of use ofType(Authentication)
.
LOGIN
is just a string not an action.
for more you can see this stackblitz
click on button Store Check
.