2015-11-03 83 views
-1

为了让我的头在这附近,我正在努力。Angularjs指令不能绑定到DOM

我有一个指令,当点击一个图像时打开一个弹出按钮。这一切都按预期工作,但点击按钮不会触发ng-click Im期待它点击,这导致我认为它不绑定到DOM。

这是我的代码,希望有人能够对此有所了解。

<img src="img.png" alt="" custom-popover 
     popover-html="<button ng-click='func()'> 
      Click here</button>" popover-placement="bottom" popover-label="Label"/> 

这里是我的指导我试着使用

app.directive('customPopover', function() { 
     return { 
      restrict: 'A', 
      template: '<span>{{label}}</span>',  
      link: function (scope, el, attrs) {   
       scope.label = attrs.popoverLabel; 
       $(el).popover({ 
        trigger: 'click', 
        html: true, 
        content: attrs.popoverHtml, 
        placement: attrs.popoverPlacement 
       }); 
      } 
     }; 
    }); 

回答

0

尝试出头这样的 - 我不保证它会工作,因为我无法测试它。

app.directive('customPopover', function ($compile) { 
    return { 
     restrict: 'A', 
     template: '<span>{{label}}</span>',  
     link: function (scope, el, attrs) {   
      scope.label = attrs.popoverLabel; 
      $(el).popover({ 
       trigger: 'click', 
       html: true, 
       content: $scompile(attrs.popoverHtml)(scope), 
       placement: attrs.popoverPlacement 
      }); 
     } 
    }; 
});