0
我正在使用ng-include加載大量數據。AngularJS ng-include finished
我想知道是否有辦法知道模板何時被「渲染」,因爲有時它看起來像被「凍結」了,因爲我想做一個「加載屏幕」或其他東西。
Thx。
下面的代碼
控制器代碼:
$scope.layout = {
current: 'single-table.html'
};
$scope.layout.get = function() {
return $scope.layout.current;
};
模板: main.html中
<div class="btn-group">
<button ng-click="layout.current = 'single-table.html'">Single</button>
<button ng-click="layout.current = 'multiple-table.html'">Multiple</button>
</div>
<div ng-include="layout.get()"></div>
單table.html
<table class="table table-bordered">
<thead>
<th ng-repeat="column in columns">{{ column.title }}</th>
</thead>
<tbody>
<tr ng-repeat="record in records">
<td ng-repeat="field in record.fields"
ng-controller="FieldController"
ng-class="getClass()">
{{ field.display }}
</td>
</tr>
</tbody>
</table>
MUL tiple-table.html
<table class="table table-bordered" ng-repeat="record in records">
<tbody>
<tr ng-repeat="field in record.fields">
<th>{{ columns[$index].title }}</th>
<td ng-controller="FieldController" ng-class="getClass()">
{{ field.display }}
</td>
</tr>
</tbody>
</table>
編輯
我使用的是1.2.0版本
一個解決方案(可能不是最好的)是這樣做的(無NG-包括)
<table class="table table-bordered" ng-show="layout.current == 'single-table.html'">
<thead>
<th ng-repeat="column in columns">{{ column.title }}</th>
</thead>
<tbody>
<tr ng-repeat="record in records">
<td ng-repeat="field in record.fields"
ng-controller="FieldController"
ng-class="getClass()">
<span lud-run="{{ field.ng_directive }}"></span>
</td>
</tr>
</tbody>
</table>
<table class="table table-bordered" ng-repeat="record in records" ng-show="layout.current == 'multiple-table.html'">
<tbody>
<tr ng-repeat="field in record.fields">
<th>{{ columns[$index].title }}</th>
<td ng-controller="FieldController" ng-class="getClass()">
<span lud-run="{{ field.ng_directive }}"></span>
</td>
</tr>
</tbody>
</table>
我只有20條記錄,但(不在代碼中),每個單元格根據數據類型(字符串,日期,日期時間,圖像...)加載自定義指令。我認爲這個「解決方案」運行兩次相同的數據(ng-show,而不是ng-if),但是當切換佈局模式時沒有「滯後」。
什麼樣的數據?請提供更多細節並顯示使用一些代碼。你嘗試了什麼? – apairet 2014-10-01 20:52:40
數據庫行。我有一個按鈕來切換佈局模式:每個記錄一個表或多個記錄的表。 – Ulrira 2014-10-01 20:56:30
您的加載屏幕應取決於填充'$ scope.records'的方法,而不是您的'ng-include'。請發佈您的服務和/或控制器代碼獲取您的數據。你可能使用'$ resource'或'$ http',你可以使用承諾來實現你需要的東西 – apairet 2014-10-01 21:21:21