如何在Angular的组件上访问TemplateRef?

问题描述 投票:0回答:1

组件TS

ngOnInit() {
    if(somecondition)
        // This is the line of code that wont work
        this.openModal(#tempName);
}

组件HTML

<ng-template #tempName>
    I got some content here
</ng-template>

this.openModal(#tempName) - >如何在这里访问ngTemplate tempName?

angular typescript ngx-bootstrap
1个回答
0
投票

Flyn你输入你的代码

@ViewChild('tempName') mymodal: ElementRef;
//You can NOT use this.mymodal at ngInit, the early time you can use is in ngAfterViewInit
ngAfterViewInit()
{
 if (somecondition)
   this.openModal(mymodal);
}
© www.soinside.com 2019 - 2024. All rights reserved.