2015-11-03 84 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 
      }); 
     } 
    }; 
});