1

我的应用程序中有 2 项服务。我用来Subject为所有应用程序发送数据。但是有一个问题,我只有一个Subject. 我StateService需要 3 个独立的 a 实例Subject

constructor(
  public currentActorSubject: Subject<string>,
  public teamRoleSubject: Subject<string>,
  public teamIdSubject: Subject<string>
) {

}

ConnectionService需要一个 a 的实例Subject

constructor(
  private stateService: StateService,
  public participantsSubject: Subject<any>
) {

}

我有 2 个不同的subscribe()方法来处理 2 个(在我看来)不同的 a 实例Subject

this.stateService.currentActorSubject.subscribe(currentActor => {
  this.currentActor = currentActor;
});
this.connectionService.participantsSubject.subscribe(participants => {
  this.participants = participants;
});

但是当我运行应用程序并检查时,我发现有 1 个实例接收所有数据。

4

0 回答 0