Robie pobieranie elementów do galerii w angularze, chciałbym po stworzeniu DOM za pomocą ng-repeat wykonać od razu funkcję która będzie formatować wczytane elementy. Dane pobierane są z WebApi. Próbowałem za pomocą dyrektywy ale nie wykonuje się ona zawsze:
Widok:
<div class="box" ng-repeat="gallery in listGallery" on-last-repeat="onEnd()">
<img id="{{gallery.id}}" class="fancyDemo" ng-src="uploadRepository/{{gallery.fileName}}" alt="">
<div class="thumb_title "><span class="text">{{gallery.title}}</span> </div>
<p class="para">{{gallery.tagsGallery}}</p>
</div>
Kontroler:
app.controller('designController', function ($scope, $http, $timeout) {
showLoader();
$http.get("api/GalleryList")
.then(function (response) {
galleryListGanerator(response.data.GalleryTitleList, 3);
$scope.listGallery = galleryVisible;
hideLoader();
galleryVisible = [];
$scope.onEnd = function () {
$timeout(function () {
alert('all done');
}, 1);
};
}, function (error) {
});
});
app.directive('onLastRepeat', function () {
return {
link: function(scope, element, attrs) {
var $container = $('#content');
$container.imagesLoaded(function () {
$container.masonry({
itemSelector: '.box',
isAnimated: true
});
});
if (scope.$last) {
scope.$eval(attrs.onLastRepeat);
}
}
};
});
Ciekawe jest że po wstawieniu "alert('all done');" javascript poprawnie sie wykonuje, a jak go usuwam to losowo. W czym może być problem? Proszę o rady