I am writing a directive below to make a function call when an element ngRepeatreceives a visualization in the user interface.
ngRepeat
Directive
directives.directive('repeatDone', function() { return { restrict: 'A', require: 'ngRepeat', link: function(scope, element, attrs, ngModel) { if (scope.$last) { scope.$eval(attrs.repeatDone); } } }; });
But this gives an error $compile. If I delete the required part, it works fine.
$compile
Why can't AngularJS accept "require:" ngRepeat "? Help will be appreciated.
require . ng-repeat . ng-repeat, . ng-repeat.
require
ng-repeat
, require, . ngModel - , , . ngModel . , require .
ngModel
, , ng-repeat, repeat-done ng-repeat. , , DOM, repeat-done, , "ng-repeat". , . ...
repeat-done
$timeout . , , $timeout .
$timeout
scope.$evalAsync scope.$eval
scope.$evalAsync
scope.$eval
$timeout, $apply() $apply $digest , DOM redered$evalAsync , DOM redered
$timeout, $apply() $apply $digest , DOM redered
$evalAsync , DOM redered
CODE
directives.directive('repeatDone', function($timeout) { return { restrict: 'A', link: function(scope, element, attrs, ngModel) { if (scope.$last) { $timeout(function () { scope.$eval(attrs.repeatDone); }); //or you can use //scope.$evalAsync(attrs.repeatDone); } } }; });
.