如何将变量传递给"data-target ="角度2 [英] How to pass variable to "data-target=" angular 2

查看:818
本文介绍了如何将变量传递给"data-target ="角度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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆