【问题标题】:Using attribute binding together with string interpolation将属性绑定与字符串插值一起使用
【发布时间】:2016-04-06 15:00:11
【问题描述】:

我想构建一个像 example on the bootstrap website 这样的手风琴,但使用 angular 2 指令 *ngFor 动态加载数据。因此我也尝试动态设置 aria-controls 的值:

[attr.aria-controls]="{{item.itemId}}"

显然不可能在角度2中将属性绑定与字符串插值一起使用。上面的代码给了我以下错误。

Parser Error: Got interpolation ({{}}) where expression was expected ...

有解决办法吗?

【问题讨论】:

    标签: twitter-bootstrap angular


    【解决方案1】:

    在这种情况下,以下内容就足够了:

    [attr.aria-controls]="item.itemId"
    

    这将评估item.itemId 表达式并将结果放入aria-controls 属性中。

    【讨论】:

      猜你喜欢
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2017-11-29
      • 1970-01-01
      • 2017-07-01
      • 2017-04-30
      • 2012-01-29
      • 1970-01-01
      相关资源
      最近更新 更多