Javascript 存储分派操作不是Angular中的构造函数
我使用ngrx存储数据。我在调用操作时遇到以下错误 _全局\u存储\u操作\u身份验证\u操作\u网页包\u导入的\u模块\u 9\u。SetAuthTokenRequest不是构造函数 myComponent.tsJavascript 存储分派操作不是Angular中的构造函数,javascript,angular,typescript,redux,ngrx,Javascript,Angular,Typescript,Redux,Ngrx,我使用ngrx存储数据。我在调用操作时遇到以下错误 _全局\u存储\u操作\u身份验证\u操作\u网页包\u导入的\u模块\u 9\u。SetAuthTokenRequest不是构造函数 myComponent.ts import * as AuthActions from "../../global/store/actions/auth.actions"; import { Token } from "../../global/models"; const tk: Token = {
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));
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);
}
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;
}
}
动作。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));
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);
}
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;
}
}
减速器.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));
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);
}
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);
}
您可以查看我的代码错误-参数属性仅允许在构造函数中使用。***构造函数(公共只读负载:令牌);private和public仅在类级别使用,而不是函数级别(它们始终是私有的)。请与mySorry再次检查您的代码,哪个.ts文件对文件检查?@shakerhussain您也可以投票支持我的答案。非常感谢。