2015-06-18 43 views
1

HTML代碼信息後:動態生成的表是臨危從服務

<table class="table table-bordered table-striped"> 
    <thead> 
     <tr> 
      <td>one</td> 
      <td>two</td> 
      <td>three</td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="color in colors"> 
      <td>{{ color.one }}</td> 
      <td>{{ color.two }}</td> 
      <td>{{ color.three }}</td> 
     </tr> 
    </tbody> 
</table> 

控制器:

var SomeController = function ($scope, SomeService, $window) { 
    var colors= []; 

    SomeService.someFunction().success(function (data, status, header, config) { 
     colors= data; 
    }).error(function (data, status, headers, config) { 
     // handle error 
    }); 
}; 

基本上,我需要動態地創建基於無論是在後臺我的表...然而,問題在於,一旦我呼叫該頁面,它會自動加載列,稍後一秒左右,它就會從服務中恢復。無論如何,我可以延遲加載時間,或讓表格「刷新」自己以顯示新數據。

+0

不包括''訂閱到像範圍'$ scope.subscriptions = data'&然後'NG-repeat'would是'TR NG重複=」訂閱的訂閱「> ​​{{subscription.one}} ​​{{subscription.two}} ​​{{subscription.three}} ' –

回答

1

聽起來像你可能可以使用ngShow,並等待您的數據解決$scope.colors這應該延遲顯示您的表,直到通話完成。請嘗試以下...

<table 
    class="table table-bordered table-striped" 
    ng-show="colors" class="ng-hide"> 
    <thead> 
     <tr> 
      <td>one</td> 
      <td>two</td> 
      <td>three</td> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="color in colors"> 
      <td>{{ color.one }}</td> 
      <td>{{ color.two }}</td> 
      <td>{{ color.three }}</td> 
     </tr> 
    </tbody> 
</table> 

SomeService.someFunction().success(function (data, status, header, config) { 
    $scope.colors = data; // let colors be defined on $scope 
}) 
+0

工作!我會確保在可以的時候將其標記爲正確的答案。謝謝! – outofmemoryerror