store dispatch actions is not a Constructor in Angular

115
January 10, 2020, at 5:30 PM

I am using ngrx for storing data. I am getting below error while calling action?

_global_store_actions_auth_actions__WEBPACK_IMPORTED_MODULE_9__.SetAuthTokenRequest is not a constructor

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));

actions.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);
}

reducer.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;
  }
}
Answer 1

This is wrong

export declare class SetAuthTokenRequest implements Action {
  payload: Token;
  readonly type = AuthActionTypes.SET_AUTH_TOKEN_REQUEST;
  constructor(payload: Token);
}

You need to change like this

   export class SetAuthTokenRequest implements Action {
      public readonly type = AuthActionTypes.SET_AUTH_TOKEN_REQUEST;
      constructor(public readonly payload: Token);
    }

You can view my code here

READ ALSO
Sort array with a search keyword - Javascript

Sort array with a search keyword - Javascript

I need to sort a javascript array within the search result with the keyword which we searchedFor example:

100
Rails 6 JavaScripts

Rails 6 JavaScripts

I'm trying to implement some JavaScript in my Rails 6 app, I have no idea if I'm going about it the right way but so far everything I've tried has been wrong

115
Animating recursive backtracking algorithm in JavaScript

Animating recursive backtracking algorithm in JavaScript

I'm stuck on trying to animate a color change in a back tracking algorithm as it happens in the recursive functionAs of now when I run the function, it updates the colors only at the end of the function

115
Is there any way to hide confirm box without heading [duplicate]

Is there any way to hide confirm box without heading [duplicate]

Is there anyway to hide the confirm box title "On embedded page on this page says"

97