删除某些元素上的子角度指令

时间:2015-12-11 13:17:57

标签: javascript angularjs angularjs-directive angular-bootstrap

我有指令

class MyDirective

  constructor: (@$compile) ->
      return {
      scope:
        var1: "="
        var2: "="
      restrict: 'A'
      templateUrl: 'views/template.html'
      }

app.directive 'emDir', ['$compile', MyDirective]

template.html具有此类型

<div uib-popover-template="dynamicPopover.templateUrl" popover-trigger="mouseenter">
</div>

这个指令在我的html上用ng-repeat重复多次。

因此,任何重复元素在mouseenter上都有一个popover。但是我只需要为某些元素设置popover,而不是全部。

我试图这样做

link = (scope, element, attrs) =>
    if scope.var1 < scope.var2
                    scope.$watch(
                          element.children().removeAttr('uib-popover-template')
                          element.children().removeAttr('popover-trigger')
                          $compile(element.children())(scope)
                    )

删除了该属性后,popover仍会在mouseenter上显示所有元素。这一个做同样的

compile: (element, attrs) =>
            pre: (scope, element, attrs) =>
                    if scope.var1 < scope.var2
                        element.children().removeAttr('uib-popover-template')
                        element.children().removeAttr('popover-trigger')

我也试过

compile: (element, attrs) =>
       if attrs.var1 < attrs.var2
            element.children().removeAttr('uib-popover-template')
            element.children().removeAttr('popover-trigger')
            element.children().removeAttr('popover-popup-close-delay')

在这种情况下,popover对所有元素都会消失,但我只需要一些元素。

我该怎么做?

0 个答案:

没有答案