【问题标题】:Angular NGXS TypeError: Cannot freeze [duplicate]Angular NGXS TypeError:无法冻结[重复]
【发布时间】:2021-04-05 22:21:57
【问题描述】:

分派动作的代码

  constructor(auth: AuthService, private store: Store) {
    this.userAuth = auth.signedIn.subscribe({ next: (user) => {
      this.user = user;
      this.store.dispatch(new SetUser(user));
    }});
  }

动作定义

import firebase from 'firebase/app';

export class SetUser {
  static readonly type = '[firebase.User | null] Add';

  constructor(public payload: firebase.User | null) {}
}

还有我的商店实现:

    @Action(SetUser)
    add({ patchState }: StateContext<UserStateModel>, { payload }: SetUser): void {
        patchState({
            user: payload
        });
    }
@State<UserStateModel>({
    name: 'user',
    defaults: {
        user: null
    }
})

【问题讨论】:

标签: javascript angular typescript ngxs


【解决方案1】:

使static readonly type = '[firebase.User | null] Add'; 成为非静态的,像这样:

static type = '[firebase.User | null] Add';

由于我们看不到您的整个代码(例如,您发布了一些没有任何类的构造函数)并且您不会让我们(参见 cmets),这是我在抱怨某些只读属性的错误消息之后的最佳猜测。

否则firebase.User中可能有一些只读属性,那怎么办?

你在 NGXS 试图冻结的存储中​​插入了一些东西。 “冻结”涉及某种在只读属性上不允许的覆盖。现在,如果我上面的两个提示没有帮助,现在由您来查找其中的只读内容。

【讨论】:

    猜你喜欢
    • 2019-02-27
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-11
    • 1970-01-01
    相关资源
    最近更新 更多