0

我正在尝试连接redux-remotedev到我的mobx-angular项目。我正在关注mobx-remotedev 此处的文档,以及如何在此处使用 Angular 的文档,但我无法安排。

我的应用程序模块:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MobxAngularModule } from 'mobx-angular';
import remotedev from 'mobx-remotedev';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ChildComponent } from './child/child.component';
import {MobxStore} from './store/mobx-store';

@NgModule({
  declarations: [
    AppComponent,
    ChildComponent,    
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    MobxAngularModule
  ],
  providers: [
    { provide: MobxStore, useClass: remotedev(MobxStore, { global: true }), deps: []}
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的 MobxStore:

import { Injectable } from '@angular/core';
import { makeObservable, observable, computed, action, flow } from "mobx";

@Injectable()
export class MobxStore {
  number1 = 0;
  constructor() {
    makeObservable(this, {
      number1: observable,
      setNumber1: action
      })
  }
  
  setNumber1() {
    this.number1++;
  }
}

我还在 polyfills.ts 中添加了这一行:

(window as any).global = window;

没有错误,状态按预期工作,但 remotedev 未连接。

提前感谢你们的帮助!

4

0 回答 0