【发布时间】:2020-01-31 01:31:08
【问题描述】:
我正在尝试通过访问选项卡元素引用来打开选项卡,但无法正常工作。我如何访问我的标签元素参考。我已经编写了 selectTab 函数。如果我们通过选项卡元素引用选项卡将打开。但它不起作用。如果有人知道,请帮助解决这个问题。
如果我使用 ngif,我会遇到 selectTab 未定义问题。
app.component.html:
<tabs #main>
<tab #subone>Content</tab>
<tab #subtwo>Content</tab>
</tabs>
<button (click)="opentab1()">Sub One</button>
<button (click)="opentab2()">Sub Two</button>
app.component.ts:
@ViewChild('main') main: ElementRef;
@ViewChild('subone') subone: ElementRef;
@ViewChild('subtwo') subtwo: ElementRef;
opentab1(){
this.main.selectTab(this.subone);
}
opentab2(){
this.main.selectTab(this.subtwo);
}
演示:https://stackblitz.com/edit/angular-tabs-example-n8qv2e?file=src/app/app.component.ts
【问题讨论】:
标签: javascript angular7 angular8