0

I got pagination in angular done in $http.get like that:

if (vm.currentPage <= 6) {
      vm.pagination = _.range(1, 11);
}
if (vm.currentPage > 6) {
    vm.pagination = _.range(vm.currentPage - 5, vm.currentPage + 5);
}
if (vm.currentPage > vm.maxPage - 5) {
      vm.pagination = _.range(vm.maxPage - 10, vm.maxPage + 1)
}


<li ng-repeat='val in vm.pagination' class="page">
   <a href="{{val}}" value="{{val}}">{{val}}</a>
</li>

I also got jquery function that i want to be execute after vm.pagination is updated on index.html:

$("a[value=" + vm.currentPage + "]").parent().addClass("active");

At this point i'm waiting to $http.get is finished, and execut jquery function after it, but still Angular add new li elements after everything is executed in controller.

How to make jquery function executed after Angular finish updated vm.pagination in view?

3
  • 2
    What's the C# for? Commented Jul 26, 2016 at 13:24
  • Possible duplicate of Toggle classes in a list with Angular Commented Jul 26, 2016 at 13:35
  • add callback to exec JQuery Commented Jul 26, 2016 at 13:37

1 Answer 1

2

You can create a custom directive

<li ng-repeat='val in vm.pagination' id="page" my-repeat-directive>
  <a href="{{val}}" value="{{val}}">{{val}}</a>
</li>

angular.module('myApp', []).directive('myRepeatDirective', function() {
  return function(scope, element, attrs) {
    angular.element(element).css('color','blue');
    if (scope.$last){
       window.alert("im the last!"); // Execute you code here
    }
  };
})

You can get more information (and an example) in the Source Answer

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.