问题描述
我正在尝试使用角度材料和 @viewChild
将组件(动态创建)附加到各个选项卡,但只有当我单击第二个选项卡中的按钮时,它才会进入第一个选项卡.
I am trying to append component (dynamic created) to respective tabs using angular material and @viewChild
but it is going to first tab only when I click button in the 2nd tab.
这里是 Stackblitz - angular-append-组件到各个选项卡
它没有显示在单个标签中.我有 3 个标签.所有 3 个选项卡都包含 Add
按钮,当我单击第一个选项卡的按钮时,它会在第一个选项卡中添加该组件,但是当我单击第二个选项卡的 Add
按钮时,它会添加该组件仅在第一个选项卡中,它应该添加到第二个选项卡中.
It's not displaying in individual tab. I have 3 tabs. all 3 tabs contains Add
button, when I click on 1st tab's button, it's adding that component in 1st tab but when I click on 2nd tab's Add
button, it's adding that component in 1st tab only, it should add in 2nd tab.
有人可以帮我弄清楚如何做到这一点吗?
Can someone please help me to figure-out how to do this?
推荐答案
这里有一个工作示例 https://stackblitz.com/edit/angular-append-component-to-respective-tabs-jp5zzt-p7nonq
使用 ViewChild,您始终可以访问第一个.使用 ViewChildren 并通过 selectedIndex 访问
With ViewChild you always access the first one. Use ViewChildren and access with the selectedIndex
这篇关于角度将组件附加到各个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!