2014-12-30 35 views
0

我有一個對象數組,我想使用ng-repeat類似於角度結構在可滾動窗口中顯示。到目前爲止,我正在使用Angular UI's utils滾動條。需要幫助爲AngularUI.util的ui-scroll指令創建一個數據源對象

我已經通讀了read me,並且在上一個關於堆棧溢出的問題上也通過this example得知了this answer。所以在我的代碼中,這是我目前所擁有的,並且它在運行時不會發生錯誤,而且它也不會顯示任何內容。

以我模塊定義:

var app = angular.module('PromoUI', ['ngRoute', 'angularUtils.directives.dirPagination', 'ui.bootstrap','ui.scroll','ui.scroll.jqlite']) 

以我的控制器:

$scope.datasource = { 
     get: function (index, count, success) { 
      success($scope.discounts) 
     } 
    } 

筆者認爲:

{{discounts[0].PromoCode}} 
    <div ui-scroll-viewport style="height:300px"> 
     <div ui-scroll="discount in datasource"> 
     <p>{{discount.PromoCode}}</p> 
     <p>{{discount.DiscountDescription}}</p> 
     </div> 
    </div> 

(注意上面{{折扣[0] .PromoCode}}正確地顯示在瀏覽器中)

我的引用是正確的:

<!--ANGULAR UI--> 
    <script src="../Scripts/angular-ui/ui-utils.js"></script> 

我有一種感覺,我不設立數據源正確。有誰可以使用這個指令給我一個手嗎?

回答

0

我認爲你有什麼有可能工作爲好,但我已經將它設置如下:

app.factory('datasource', ['$timeout', function($timeout) { 
 
     var a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']; 
 
     var get = function (index, count, success) { 
 
      return success(a); 
 
     }; 
 
     return { 
 
      get: get 
 
     }; 
 
    } 
 
]);

我有這個plnkr在http://plnkr.co/edit/W8Mzee

+0

我忘了提及你的數據源是用頁面加載編譯的,所以如果$ scope.discounts沒有被定義,那麼你就不會看到一個東西。 – Ilantoren