【发布时间】:2017-12-05 13:12:22
【问题描述】:
我正在学习 Angular 5,我一直在尝试使用 .next 方法添加 data.service.ts 在尝试这个:
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
@Injectable()
export class DataService {
private go = new BehaviorSubject<any>([' First Goal','Second Goal']);
newvar = this.go.asObservable();
constructor() { }
changeGoal(newvar){
this.newvar.next(this.go);
}
}
我得到了这个错误:“属性'next'不存在于类型'Observable'上”;
【问题讨论】:
-
我发现这个解决方案只需更改一行“this.go.next(this.newvar);”
-
供以后参考,错误的原因是
next(...)是RxJS主题的成员,而不是可观察的。这就是您的上述解决方案有效的原因。
标签: angular5