NgRx 操作负载未达到效果 - 无错误
NgRx Action Payload not hitting Effect - No Errors
我已经检查了关于 SO 的所有可能答案,但似乎无法正确回答。
我正在将有效负载传递给操作 'GetUser'。
我希望此有效负载通过效果传递,并最终通过 http 请求发送到 API,但似乎我的效果根本没有受到影响。控制台或 ngrx 开发工具中什么也没有。
我的代码看起来不错,没有编译错误 - 怎么了?
效果如下:
@Injectable()
export class LoginEffects {
env = environment;
constructor(private actions: Actions, private http: HttpClient, private store: Store<any>) {
}
@Effect()
getUser$: Observable<Action> = this.actions.pipe(
ofType<GetUser>(LoginActions.GET_USER),
switchMap((action) => {
console.warn(action.payload);
console.warn(action.payload);
console.warn(action.payload);
return this.http.post(this.env.urlDefault + '/authenticate', action.payload).pipe(
map((data) => new LoginActions.GetUserSuccess( data )),
catchError(error => of(new LoginActions.GetUserFail( error ))));
}));
}
这是行动:
import { Action } from '@ngrx/store';
export const GET_USER = 'GET_USER';
export const GET_USER_FAIL = 'GET_USER_FAIL';
export const GET_USER_SUCCESS = 'GET_USER_SUCCESS';
export class GetUser implements Action {
readonly type = GET_USER;
constructor(public payload: any) {
console.log('GetUser Action Hit!');
}
}
export class GetUserFail implements Action {
readonly type = GET_USER_FAIL;
constructor(public payload: any) {
console.log('GetUserFail Action Hit!');
}
}
export class GetUserSuccess implements Action {
readonly type = GET_USER_SUCCESS;
constructor(public payload: object) {
console.log('GetUserSuccess Action Hit!');
}
}
export type LoginActions = GetUser | GetUserFail | GetUserSuccess;
你在模块中注册了效果吗?
将以下行添加到您的模块导入部分
@NgModule({
imports: [
...
EffectsModule.forRoot([AppEffects])
],
...
})
我已经检查了关于 SO 的所有可能答案,但似乎无法正确回答。
我正在将有效负载传递给操作 'GetUser'。
我希望此有效负载通过效果传递,并最终通过 http 请求发送到 API,但似乎我的效果根本没有受到影响。控制台或 ngrx 开发工具中什么也没有。
我的代码看起来不错,没有编译错误 - 怎么了?
效果如下:
@Injectable()
export class LoginEffects {
env = environment;
constructor(private actions: Actions, private http: HttpClient, private store: Store<any>) {
}
@Effect()
getUser$: Observable<Action> = this.actions.pipe(
ofType<GetUser>(LoginActions.GET_USER),
switchMap((action) => {
console.warn(action.payload);
console.warn(action.payload);
console.warn(action.payload);
return this.http.post(this.env.urlDefault + '/authenticate', action.payload).pipe(
map((data) => new LoginActions.GetUserSuccess( data )),
catchError(error => of(new LoginActions.GetUserFail( error ))));
}));
}
这是行动:
import { Action } from '@ngrx/store';
export const GET_USER = 'GET_USER';
export const GET_USER_FAIL = 'GET_USER_FAIL';
export const GET_USER_SUCCESS = 'GET_USER_SUCCESS';
export class GetUser implements Action {
readonly type = GET_USER;
constructor(public payload: any) {
console.log('GetUser Action Hit!');
}
}
export class GetUserFail implements Action {
readonly type = GET_USER_FAIL;
constructor(public payload: any) {
console.log('GetUserFail Action Hit!');
}
}
export class GetUserSuccess implements Action {
readonly type = GET_USER_SUCCESS;
constructor(public payload: object) {
console.log('GetUserSuccess Action Hit!');
}
}
export type LoginActions = GetUser | GetUserFail | GetUserSuccess;
你在模块中注册了效果吗? 将以下行添加到您的模块导入部分
@NgModule({
imports: [
...
EffectsModule.forRoot([AppEffects])
],
...
})