我有一個顯示預加載器的div。只有在我的所有數據在我的重複中完成加載後,我纔想隱藏該div。AngularJS在中繼器完成後隱藏預加載器
Plunker:http://plnkr.co/edit/ilgOZzIy2axSi5Iy85C7?p=preview
HTML:
<div ng-controller="locationAccordionCtrl">
<div ng-repeat="location in locations" on-finish-render="ngRepeatFinished">
{{location.siteName}}
<ul>
<li ng-repeat="listOfLocations in location.locationsList track by $index">
{{listOfLocations}}
</li>
</ul>
</div>
</div>
控制器:
App.controller('locationAccordionCtrl', function ($scope) {
$scope.locations = [
{
"siteName":"First Location",
"locationsList":['First Location 1', 'First Location 2', 'First Location 3']
},
{
"siteName":"Second Location",
"locationsList":['Second Location 1', 'Second Location 2', 'Second Location 3']
},
{
"siteName":"Third Location",
"locationsList":['Third Location 1', 'Third Location 2', 'Third Location 3']
}
];
// Hide preloader after repeater is finished loading data
App.directive('onFinishRender', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attr) {
if (scope.$last === true) {
$timeout(function() {
scope.$emit('ngRepeatFinished');
});
}
}
}
});
// hide preloader
$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
$scope.hidePreLoader = true;
});
});
你能得到這個在plunker工作? http://plnkr.co/edit/ilgOZzIy2axSi5Iy85C7?p=preview – simple