【问题标题】:Non-compiled directive of child tag in ngRepeat parentng中子标签的未编译指令重复父项
【发布时间】:2016-10-25 14:24:59
【问题描述】:

我想要 uibTooltip 指令而不是原生的 title HTML 属性。然后,我得到了一个指令,它在编译之前提供了属性的自动排列。

如果带有受影响属性的标签在里面,问题就出在 ngRepeat 指令中。

你可以看到here(一个JSFiddle测试示例)。

【问题讨论】:

  • 请详细说明您的问题或疑问。
  • 单击 JSFiddle 链接。您将看到两个按钮组之间的不同行为。第二个是错误的。为什么?

标签: angularjs angularjs-directive angularjs-ng-repeat


【解决方案1】:

因为这个指令使用终端并且当你在<li>中使用按钮时

<li><button type="button" ng-repeat="btn in vm.buttons" class="btn btn-default" title="Add" ng-click="vm.add()"><span class="glyphicon glyphicon-plus"></span></button></li>

这个link 很好地解释了终端和优先级。

【讨论】:

  • 所以,我永远不能将这个终端指令与 ngRepeat 指令混合使用,对吧?
  • 你可以喜欢你用过的第一个例子。
  • 什么!?什么意思?
  • 您可以将其用作<button type="button" ng-repeat="btn in vm.buttons" class="btn btn-default" title="Add" ng-click="vm.add()"><span class="glyphicon glyphicon-plus"></span></button> 指令,并且 ng-repeat 应该在同一个标​​签上
  • 我知道。我得考虑一下,作为子标签,有没有解决办法?
【解决方案2】:

Here 是一个解决方案!如果我们在postLink函数里面编译就成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-26
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    相关资源
    最近更新 更多