Angular 不带视图的动态组件上的输出

Angular 不带视图的动态组件上的输出,angular,angular-dynamic-components,Angular,Angular Dynamic Components,在Angular 8项目中,我使用以下代码创建了一些没有viewref的dynmic组件: const componentFactory = this.componentFactoryResolver.resolveComponentFactory(HelloComponent); const componentRef = componentFactory.create(this.injector); componentRef.changeDetectorRef.detectChan

在Angular 8项目中,我使用以下代码创建了一些没有viewref的dynmic组件:

const componentFactory = this.componentFactoryResolver.resolveComponentFactory(HelloComponent);
const componentRef = componentFactory.create(this.injector);      
componentRef.changeDetectorRef.detectChanges();    
componentRef.instance.slideContentRendered.pipe(first()).subscribe(x => {console.log('does not work', x);});
在HelloComponent本身中,我正在等待一些异步任务完成,然后发出slideContentRendered,但我没有进入subscribe方法主体

这里您可以看到一个示例应用程序

我如何访问输出? 如果我使用以下代码对viewref进行相同的尝试,它会起作用:

const componentRef = viewContainerRef.createComponent(componentFactory);
componentRef.instance.slideContentRendered.pipe(first()).subscribe(x => {console.log('it works', x);});

使用BehaviorSubject,只要某个地方有侦听器,它就会发出值。订阅EventEmitter仅在发送时存在直接侦听器时触发。下面的变化也是如此:

slideContentRendered=newbehaviorsubject('hey');
ngAfterViewInit(){
log('AfterViewInitTriggered');
this.slideContentRendered.next('teeest!')
}
触发器(){
this.testService.renderHtmlFromPresentation().subscribe(x=>console.log(x));
}

使用BehaviorSubject,只要某个地方有侦听器,它就会发出值。订阅EventEmitter仅在发送时存在直接侦听器时触发。下面的变化也是如此:

slideContentRendered=newbehaviorsubject('hey');
ngAfterViewInit(){
log('AfterViewInitTriggered');
this.slideContentRendered.next('teeest!')
}
触发器(){
this.testService.renderHtmlFromPresentation().subscribe(x=>console.log(x));
}