当前位置: 首页 > 工具软件 > ng-packagr > 使用案例 >

ng-packagr 打包报错 Public property X of exported class has or is using name 'Observable' from external ...

赵俊晤
2023-12-01

old

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

@Injectable({
  providedIn: 'root'
})
export class DataService {
  private dataSource = new BehaviorSubject(Object);
  public currentData = this.dataSource.asObservable();

  constructor() {}

  changeData(data) {
    this.dataSource.next(data);
  }
}

new :红色部分是重点 

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

@Injectable({
  providedIn: 'root'
})
export class DataService {
  private dataSource = new BehaviorSubject(Object);
  public currentData: Observable<Object> = this.dataSource.asObservable();

  constructor() {}

  changeData(data) {
    this.dataSource.next(data);
  }
}

问题:可观测属性的问题,

 

当我使用的是可观测的属性,但找不到它。要解决这个问题,我需要简单地添加缺少的可观察导入,并在当前数据变量中键入:然后就可以解决了

转载于:https://www.cnblogs.com/fuzitu/p/10510994.html

 类似资料: