gpt4 book ai didi

angular - 如何访问 Angular 组件上的 TemplateRef?

转载 作者:行者123 更新时间:2023-12-03 16:24:28 24 4
gpt4 key购买 nike

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

关于angular - 如何访问 Angular 组件上的 TemplateRef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52109046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com