2016-01-23 97 views
2

我想通過BootstrapUI的popover指令傳遞一個函數。該屬性通常是一個字符串,但我需要做一個AJAX調用來爲該指令提供屬性。目前,彈出窗口將該功能顯示爲一個字符串,例如「showItem(one)」而不是調用該函數的結果,例如, 「項目是一個」。謝謝!AngularJS和BootstrapUI - 將函數和參數傳遞給BootstrapUI指令

的HTML

<li ng-repeat="item in items" 
     popover-placement="top" 
     popover-trigger="mouseenter" 
     uib-popover="showItem({{item.id}})"> 
     {{item.id}} 
    </li> 

的JS

app.controller("uibController", ["$scope", function ($scope) { 
$scope.items = [ 
    {id: "one"}, 
    {id: "two"}, 
    {id: "three"} 
]; 
$scope.showItem = function(item){ 
    $http.get('url').success(function(response){ 
    //data for popover directive 
    return "Item is " + item.id; 
}) 

}; 
}]); 

Codepen http://codepen.io/anon/pen/PZQOdY

回答

1

<div ng-repeat="item in items" 
 
      popover-placement="bottom" 
 
      popover-trigger="mouseenter" 
 
      uib-popover="{{showItem(item)}}"> 
 
      {{item.id}} 
 
     \t </div>

+1

p租賃更新你的html標記,以上述方式 – saikumar

+0

我有點失敗,這工作正常,但我的意思是模擬showItem中的ajax調用,我將嘗試編輯codepen以模擬ajax響應。謝謝 – doku

+0

我沒有得到,你可以更新codepen ... – saikumar

相關問題