小编Cla*_*len的帖子

为什么我收到"订阅不是函数"错误?

我有一个组件,允许用户从端口列表中选择一个选项.一旦他们做出选择,他们点击"连接端口"按钮.这会调用服务来存储选定的端口,以便将其存储为字符串.

此步骤的UI屏幕截图.

我正在获取控制台日志,显示组件成功调用服务并按原样存储.但是,在任何其他组件中,如果我尝试使用订阅调用该服务; 我收到错误.

港口服务

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

export interface Port {
  portName: String;
}

@Injectable({
   providedIn: 'root'
})
export class PortService {

activePort;

constructor() { }

setPort(port) {
  console.log('The port: ', port);
  this.activePort = port;
}

getPort(): Observable<Port> {
  console.log('The port for the application runtime: ', this.activePort);
   return this.activePort;
  }
}
Run Code Online (Sandbox Code Playgroud)

应用组件

import { Component, OnInit } from '@angular/core';
import { } from 'electron';
import * as Serialport from 'serialport';
import …
Run Code Online (Sandbox Code Playgroud)

subscribe rxjs angular

3
推荐指数
1
解决办法
781
查看次数

标签 统计

angular ×1

rxjs ×1

subscribe ×1