我正在用代码执行此操作,以便处理来自多个组件的多个视图
https://stackblitz.com/edit/angular-cy8jza?file=src/app/app.service.ts(检查控制台中的错误)
export class ViewGroup {
_onViewChanged: any;
OnViewChanged$ : Observable<any>;
_onViewAdded: any;
OnViewAdded$ : Observable<any>;
_onViewRemoved: any;
OnViewRemoved$ : Observable<any>;
viewsSet = new Set<string>();
currentView = "";
previousView = "";
constructor(){
this.OnViewChanged$ = Observable.create(obs => this._onViewChanged = obs);
this.OnViewAdded$ = Observable.create(obs => this._onViewAdded = obs);
this.OnViewRemoved$ = Observable.create(obs => this._onViewRemoved = obs);
}
}
我在代码中的位置
this._availableView.set(name, new ViewGroup());
然后致电
this._availableView.get(group)._onViewAdded.next(view);
但是我无法调用下一个,这是未定义的。
程序完全相同
this.onGroupAdded$ = Observable.create(e => this._onGroupAdded = e)
但是这一项可以在堆栈闪电战中发挥作用