1

我正在尝试使用 Angular 6 + Ngxs + WebSocket 构建应用程序。但是,有些我无法连接到 Ngxs 提供的 WebSocket 插件。

在文档中,Ngxs 提到我们可以使用 WebsocketMessageError 操作来捕获错误。(我希望我正确理解了文档)

文档链接:https ://ngxs.gitbook.io/ngxs/plugins/web-socket

但我试图在我的服务类中导入这个动作,然后它说动作不可用。

这是我的 WebSocketService 类的代码。

import { Injectable } from '@angular/core';
import { Store, Actions, ofActionDispatched } from '@ngxs/store';
import { WebsocketMessageError, ConnectWebSocket } from '@ngxs/websocket-plugin';
import * as Rx from 'rxjs';


@Injectable({
  providedIn: 'root'
})

export class WebSocketService {


  private subject: Rx.Subject<MessageEvent>;

  constructor(private store: Store, private actions$: Actions) {
    this.actions$
      .pipe(ofActionDispatched(WebsocketMessageError))
      .subscribe(({ payload }) => {
        console.log('Got action: ', payload);
      });
  }
  public connect() {
    this.store.dispatch(new ConnectWebSocket());
  }

}

我收到以下错误:

模块 @ngxs/websocket-plugin/ngxs-websocket-plugin"' 没有导出成员 'WebsocketMessageError'。

导入 WebsocketMessageError

4

1 回答 1

0

这看起来像一个错误。请在 github 存储库中报告: https ://github.com/ngxs/store/issues

于 2018-07-16T13:46:34.573 回答