Reputation: 1
I have a question about ng-repeat. I have this webpage where I upload pictures getting them from a json response, and I added a plugin (flex-images), which handles the pictures size and look. The fact is : the plugin works only if the picture array gets refreshed, but it does not happen when I remove items from the picture array. My question is : how can I force ng-repeat to refresh? The code is below, thanks in advance:
app.directive('onLastRepeat', function() {
return function(scope, element, attrs) {
if (scope.$last) setTimeout(function() {
$('#items').flexImages({ rowHeight: 500 });
}, 1);
};
});
app.controller('customersCtrl', function($scope, $http, $rootScope, $window, $location, $timeout, ngDialog, toaster, $sce) {
$scope.deletePicture = function(id,index) {
$scope.pictures.splice(index, 1);
};
});
Upvotes: 0
Views: 2642
Reputation: 473
There is no need to refresh your view. Just remove the data from your $scope.pictures
using splice
method the way you did and then push the updated data into $scope.pictures
like:
$scope.pictures.push(updated_data);
Upvotes: 1
Reputation: 13238
You do not need to reload anything. Angular will observe the changes on the object passed to ng-repeat
and automatically re-renders the view by computing $digest
on the scope.
Upvotes: 1