【发布时间】:2016-07-16 23:30:03
【问题描述】:
我想知道是否可以在组件中使用Observables,还有哪些其他组件可以订阅?
BugListComponent - 组件被注入到我加载所有服务的 boot.ts 文件中(boostrap 所在的位置)
import {Subject, BehaviorSubject} from 'rxjs/Rx';
viewBugList$: Subject<boolean>;
constructor() {
this.viewBugList$ = new BehaviorSubject<boolean>(false);
}
// Called from template, sends in 'true'
private enableIEview(enable: boolean) {
if(enable) {
this.viewBugList$.next(true);
}
}
BugListContainerComponent
import {BugListComponent} from '../buglist/bug-list.component';
initView: boolean;
constructor(private _bugListComp: BugListComponent) {
this.initView = false;
}
ngOnInit() {
this._bugListComp.viewBugList$.subscribe(e => {
if(e != null) {
this.initView = e;
}
});
}
所以,到目前为止,当从 BugListComponent 调用 .next 时,BugListContainerComponent 中的“订阅”似乎没有受到影响。
我错过了什么? 谢谢!
【问题讨论】:
标签: asynchronous angular reactive-programming observable