识别元素是指令上的超链接

时间:2015-04-22 06:41:59

标签: angularjs angularjs-directive

我有一个自定义指令,如下所示。您能告诉我如何从中过滤超链接元素吗?换句话说,如何识别元素是超链接?提前谢谢。

app.directive('toggler', function ($document) {
  return {
    link: function (scope, element, attrs, ctrl) {
      scope.open = false;

      element.on('click', function (e) {
        scope.$apply(function () { 
          scope.open = true;      //onclick open tooltip and call digest so the ng-if see the change
        });
        e.stopPropagation(); //stop event from bubbling up to document object
      });

    }
  }
});

1 个答案:

答案 0 :(得分:1)

检查tagName属性。 demo

if (element[0].tagName === 'A') {}