如何将变量传递给"data-target ="角度2 [英] How to pass variable to "data-target=" angular 2
问题描述
我正在使用angular 2打字稿,我想创建一个切换折叠列表.
这很简单,只有一个ID和data-target
,但我在列表中循环浏览,所以我有动态ID名称.我想在我的data-target
中传递一个变量,以便获取ID的动态名称.像这样的东西:
I'm working with angular 2 typescript and i want to create a toggle collapse list.
This is simple with single id and data-target
but i loop throught a list so i have dynamic id names. I want to pass a variable in my data-target
so i can reach the dynamic names of the id's. something like this:
<a data-toggle="collapse" data-target="#{{theme.themeId}}>collapseHere </a>
但这给了我一个语法错误.
<a data-toggle="collapse" data-target="#{{theme.themeId}}>collapseHere </a>
but this gives me a syntax error.
是否可以使用data-target
传递变量?
Is it possibly to pass variables with a data-target
?
推荐答案
您可以使用属性绑定.像这样的东西:
You could used attribute binding. Something like that:
[attr.data-target]="'#' + theme.themeId"
这篇关于如何将变量传递给"data-target ="角度2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!