我试图在ngRx中实现一个效果。我导入了"effect";从"@ngrx/effects",但它显示错误"模块"@ngrx/effects"没有导出成员" ts(2305)">
import { Actions, ofType, Effect } from "@ngrx/effects";
import { switchMap } from "rxjs/operators";
import * as AuthActions from './auth.actions';
type loginResponse = { token: string, message: string, loggedIn: boolean, time: number };
export class AuthEffects {
@Effect
login = this.actions$.pipe(
ofType(AuthActions.LOGIN),
switchMap((authData: AuthActions.Login) => {
return this.http
.post<loginResponse>(
'http://localhost:3000/user/signup',
{
email: authData.payload.email,
password: authData.payload.password
}
)
})
)
constructor(private actions$: Actions, private http: HttpClient) { }
}
我正在尝试使用ngRx中的效果实现登录系统。我导入了"effect";从"@ngrx/effects",但它显示错误"模块"@ngrx/effects"没有导出成员" ts(2305)">
看起来你正在尝试使用@ngrx/effects库中的@Effect,但是你共享的错误消息显示在@ngrx/effects模块中没有导出名为Effect的成员。
我认为这是因为这个错误是你正在使用旧版本的@ngrx/效果库。在版本8中,Effect装饰器被修改为createEffect函数。
它看起来像这样:
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { switchMap } from 'rxjs/operators';
import { AuthActions } from './auth.actions';
type loginResponse = { token: string, message: string, loggedIn: boolean, time: number };
export class AuthEffects {
login$ = createEffect(() =>
this.actions$.pipe(
ofType(AuthActions.LOGIN),
switchMap((authData: AuthActions.Login) => {
return this.http
.post<loginResponse>(
'http://localhost:3000/user/signup',
{
email: authData.payload.email,
password: authData.payload.password
}
)
})
)
);
constructor(private actions$: Actions, private http: HttpClient) {}
}