0

我想上使用.popover以下(從我的模板):爲什麼bootstrap popover在我的主模板指令中不起作用?

<li ng-repeat="(pid, product) in myProducts" class="status-indicator p{{pid}} {{product.status ? '' : 'disabled'}}" 
       data-original-title="<?php echo _('Product status'); ?>" 
       data-content="{{product.description}}: {{product.status ? '<?php echo _('enabled'); ?>' : '<?php echo _('disabled'); ?>'}}" status-indicator></li> 

酥料餅不會從我的主要工作指令:

spampanel.directive('domainTable', function() { 
    return { 
     replace:true, 
     template: $('#domainTableTemplate').html(), 
     link: function(scope, elem, attrs) { 
      $(".status-indicator").popover({ 
       placement: 'right', 
       trigger: 'hover' 
      }); 
     } 
    }; 
}); 

我嘗試了很多東西在這裏,沒有任何工作。

如果我做這些「禮」元素另一個指令而言,它會工作,但只有$適用於:

spampanel.directive('statusIndicator', function() { 
    return { 
     link: function(scope, elem, attrs) { 
      scope.$apply(); 
      elem.popover({ 
       placement: 'right', 
       trigger: 'hover' 
      }); 
     } 
    }; 
}); 

爲什麼我必須使用$申請正常的工作?如果我不使用$ apply,大括號之間的所有內容都會出現未評估的「{{...}}」。

看起來好像我強迫某件事在正常時間之前執行,這對我來說似乎並不合適。如果有時間和地點我應該放置這個popover,何時何地?

我寧願只在這裏有一個指令,但我怎麼能使它工作?

回答

1

angularjs不知道哪個是angularjs庫之外所做的任何更改,所以你應該$scope.$apply()包裝你的代碼...

這裏是非常好的文章約$scope.$apply() ...

除此之外您可以檢查角度-UI-引導庫,以更好地瞭解如何編寫代碼的指令......

這裏是angular-ui-popover

+0

看起來像角-UI-酥料餅是米更好的解決方案即我不想一開始就切換,但它現在更有意義。謝謝! – Kesarion

相關問題