Padraig
Padraig

Reputation: 3717

How do I control the evaluation order of Angular directives?

I have this directive - it enables the jQuery Autocomplete on Angular

var myModule = angular.module('MyModule', []).directive('autoComplete', function($timeout) {
return function(scope, iElement, iAttrs) {
        iElement.autocomplete({
            source: scope[iAttrs.uiItems],
            select: function() {
                $timeout(function() {
                  iElement.trigger('input');
                }, 0);
            }
        });
   };
});

I have another function

$scope.copy_row = function(index) {
    alert($scope.options[index].my_value);
}

This gets triggered by the ng-change directive.

Problem is - I want autocomplete directive to fire before the ng-change directive.

Works fine on all browsers except for IE. In IE ng-change fires before the autocomplete. I don't want that.

How do I modify this code so that angular fires the autocomplete directive before the ng-change directive? It has something to do with setting priority but I don't know how.

Upvotes: 0

Views: 635

Answers (1)

Erstad.Stephen
Erstad.Stephen

Reputation: 1035

You are looking to set a priority on your custom directive. The $compile will be called, walks through the DOM and gets all directives. It then uses the priority to order the directives and then links them.

http://www.ng-newsletter.com/posts/directives.html

http://docs.angularjs.org/guide/directive

Upvotes: 2

Related Questions