如何访问 Angular 组件上的 TemplateRef?

How to access TemplateRef on the component of Angular?

Component TS

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

Component HTML

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

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

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);
}