ViewContainerRef, ComponentFactoryResolver에 대해 읽었습니다. 기본적으로새로운 html 요소에 각도 요소를 동적으로 추가
: 당신의 HTML에서
넣어 태그
이 당신의 TS에 다음과 같은 선언 @ViewChild ('부모', {읽어 ViewContainerRef}) 부모 : ViewContainerRef을;
다음을 사용하여 구성 요소를 인스턴스화하십시오. const childComponent = this.componentFactoryResolver.resolveComponentFactory (ChildComponent); this.parent.createComponent (childComponent);
그러나 페이지로드시 HTML에서 이미 작동하지 않습니다.
문제는 Google지도 api (지도의 어딘가를 클릭하면 나타나는 팝업)를 사용하여 생성되는 팝업을 사용하고 있다는 것입니다. 그러나
marker.addListener('click',() => {
infowindow.open(this.map, marker);
const childComponent = this.componentFactoryResolver.resolveComponentFactory(CentreDetailsComponent);
this.parent.createComponent(childComponent);
});
그렇지 않습니다 : 팝업이
var infowindow = new google.maps.InfoWindow({
// content: this.contentString
content: " <div #parent></div>"
});
따라서 나는 다음과 같은 팝업에 온 클릭 이벤트에 바인딩하려고 나타난 후
나는 DIV 부모 태그를 넣을 필요 스크린 샷에 따라 작업하십시오. div 상위 태그가 페이지로드에서 생성되지 않았기 때문입니까? 누군가가 도와 주실 수 있습니까? Thx