[英]store dispatch actions is not a Constructor in Angular
我正在使用 ngrx 來存儲數據。 調用操作時出現以下錯誤?
_global_store_actions_auth_actions__WEBPACK_IMPORTED_MODULE_9__.SetAuthTokenRequest 不是構造函數
myCompoment.ts
import * as AuthActions from "../../global/store/actions/auth.actions";
import { Token } from "../../global/models";
const tk: Token = {
access_token: "string",
};
this.store.dispatch(new AuthActions.SetAuthTokenRequest(tk));
動作.ts
import { Action } from "@ngrx/store";
import { Token } from "../../models/token";
export declare enum AuthActionTypes {
SET_AUTH_TOKEN_REQUEST = "[Core] SET_AUTH_TOKEN_REQUEST",
export interface AuthenticationData {
user: string;
password: string;
}
export declare class SetAuthTokenRequest implements Action {
payload: Token;
readonly type = AuthActionTypes.SET_AUTH_TOKEN_REQUEST;
constructor(payload: Token);
}
減速器.ts
import { Token } from "../../models";
import { AuthAction, AuthActionTypes } from "../actions";
export interface AuthState {
token: Token;
unverifiedUserToken: Token;
}
const initialValue: AuthState = {
token: null,
unverifiedUserToken: null
};
export function auth(state = initialValue, action: AuthAction): AuthState {
switch (action.type) {
case AuthActionTypes.SET_AUTH_TOKEN_REQUEST:
return {
...state,
token: action.payload
};
default:
return state;
}
}
這是錯誤的
export declare class SetAuthTokenRequest implements Action {
payload: Token;
readonly type = AuthActionTypes.SET_AUTH_TOKEN_REQUEST;
constructor(payload: Token);
}
你需要像這樣改變
export class SetAuthTokenRequest implements Action {
public readonly type = AuthActionTypes.SET_AUTH_TOKEN_REQUEST;
constructor(public readonly payload: Token);
}
你可以在這里查看我的代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.