其他分享
首页 > 其他分享> > ng-packagr 打包报错 Public property X of exported class has or is using name 'Observable' from

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

作者:互联网

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);
  }
}

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

 

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

标签:Observable,cannot,报错,dataSource,import,Injectable,data,BehaviorSubject
来源: https://www.cnblogs.com/fuzitu/p/10510994.html