【发布时间】:2018-10-29 05:43:01
【问题描述】:
我一直在谷歌搜索,对 angular 5/6 还是有点陌生,但我正在尝试看看是否有可能。
问题
假设我有一个模板:
<ng-template #rt let-r="result" let-t="term">
<ngb-highlight [result]="r.typeAheadDisplayName" [term]="t" ></ngb-highlight>
<span *ngIf="r.primaryName ">(alias for {{ r.primaryName }}) </span>{{ r.metaData }}
</ng-template>
在此模板中,将生成一个按钮,可用作选择选项的一种方式。但是,出于特定原因,我需要能够定位按钮数组的:first-child。
我知道我可以选择元素/模板:
@ViewChild('rt') rt : TemplateRef<any>;
但是,我真的可以做一个类似于 jQuery 的 .find 甚至在 AngularJS 中的函数,来定位在这个模板中可以找到的元素。我一直在谷歌搜索,无法找到答案。
【问题讨论】:
-
使用
rt.nativeElement
标签: angular