请给我一些关于我的应用程序的解决方法的想法!我试图在我的组件中动态切换模板,但有奇怪的行为.谢谢!这是stackblitz
基本上我想要的是:我想从我的警报组件中的服务接收异步数据(节点),并在我的#initTemplate中显示此数据(节点),然后我想获取此数据的id(节点),用此发送请求id并获取我希望在#stylesTemplate中显示的其他数据(样式).两个模板都在我的警报组件中.
我的问题是什么? 我意识到我的组件需要的行为,但这不是我需要的......我在做什么:1.点击"pushData"按钮2.查看我的警报组件3.单击更改模板按钮(!!组件消失!!) 4.再次单击"pushData"5.使用更改的模板查看我的组件
我需要切换组件的模板而不会消失.
这是我的简化警报组件(另见stackblitz工作示例)
class AlertComponent implements OnInit, OnDestroy {
private subscription: Subscription;
message: any;
node$: Observable<{}>;
styles$: Observable<{}>;
constructor(private dataService: DataService) { }
activeInit: boolean = true;
ngOnInit() {
this.node$ = this.dataService.getAsyncData().pipe(share());
this.styles$ = this.node$.pipe(
mergeMap(node => {
if(!!node) {
// I need node here, because getSecondAsyncData send request with this data
return this.dataService.getSecondAsyncData(node);
}
else return of(null);
}));
}
ngOnDestroy() {
}
openSecond() {
this.activeInit = false;
} …Run Code Online (Sandbox Code Playgroud)