The directive cannot require: ngRepeat '

I am writing a directive below to make a function call when an element ngRepeatreceives a visualization in the user interface.

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.

Why can't AngularJS accept "require:" ngRepeat "? Help will be appreciated.

+4
source share
2 answers

require . ng-repeat . ng-repeat, . ng-repeat.

, require, . ngModel - , , . ngModel . , require .

, , ng-repeat, repeat-done ng-repeat. , , DOM, repeat-done, , "ng-repeat". , . ...

+7

$timeout . , , $timeout .

scope.$evalAsync scope.$eval

$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);
            }
        }
    };
});

.

+2

All Articles