diff --git a/src/ng/compile.js b/src/ng/compile.js index a4e44f0177cb..fce6f34eb4b7 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1095,7 +1095,7 @@ function $CompileProvider($provide) { childLinkFn && childLinkFn(scope, linkNode.childNodes, undefined, boundTranscludeFn); // POSTLINKING - for(i = 0, ii = postLinkFns.length; i < ii; i++) { + for(i = postLinkFns.length - 1; i >= 0; i--) { try { linkFn = postLinkFns[i]; linkFn(scope, $element, attrs, @@ -1328,7 +1328,7 @@ function $CompileProvider($provide) { } directives.push({ - priority: 100, + priority: -100, compile: valueFn(function attrInterpolateLinkFn(scope, element, attr) { var $$observers = (attr.$$observers || (attr.$$observers = {})); @@ -1346,6 +1346,7 @@ function $CompileProvider($provide) { // register any observers if (!interpolateFn) return; + // TODO(i): this should likely be attr.$set(name, iterpolateFn(scope) so that we reset the actual attr value attr[name] = interpolateFn(scope); ($$observers[name] || ($$observers[name] = [])).$$inter = true; (attr.$$observers && attr.$$observers[name].$$scope || scope). diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index fa953419c02c..ee613a6e5749 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -958,7 +958,7 @@ var VALID_CLASS = 'ng-valid', * * - * + * */ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$parse', function($scope, $exceptionHandler, $attr, $element, $parse) { diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index f164ca7a9929..5e28c62bf0ce 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -96,19 +96,25 @@ describe('$compile', function() { directive('div', function(log) { return { restrict: 'ECA', - link: log.fn('1') + link: { + pre: log.fn('pre1'), + post: log.fn('post1') + } }; }); directive('div', function(log) { return { restrict: 'ECA', - link: log.fn('2') + link: { + pre: log.fn('pre2'), + post: log.fn('post2') + } }; }); }); inject(function($compile, $rootScope, log) { element = $compile('
')($rootScope); - expect(log).toEqual('1; 2'); + expect(log).toEqual('pre1; pre2; post2; post1'); }); }); }); @@ -206,7 +212,7 @@ describe('$compile', function() { '') ($rootScope); expect(element.text()).toEqual('Hello angular'); - expect(log).toEqual('H; M; L'); + expect(log).toEqual('L; M; H'); })); @@ -387,7 +393,7 @@ describe('$compile', function() { element = $compile( '') ($rootScope); - expect(log).toEqual('H; M; L'); + expect(log).toEqual('L; M; H'); })); }); @@ -511,8 +517,7 @@ describe('$compile', function() { ($rootScope); $rootScope.$digest(); expect(element.text()).toEqual('Replace!'); - // HIGH goes after MEDIUM since it executes as part of replaced template - expect(log).toEqual('MEDIUM; HIGH; LOG'); + expect(log).toEqual('LOG; HIGH; MEDIUM'); })); @@ -521,7 +526,7 @@ describe('$compile', function() { ($rootScope); $rootScope.$digest(); expect(element.text()).toEqual('Append!'); - expect(log).toEqual('HIGH; LOG; MEDIUM'); + expect(log).toEqual('LOG; HIGH; MEDIUM'); })); @@ -1079,7 +1084,7 @@ describe('$compile', function() { expect(log).toEqual( 'first-C; FLUSH; second-C; last-C; third-C; ' + 'first-PreL; second-PreL; last-PreL; third-PreL; ' + - 'third-PostL; first-PostL; second-PostL; last-PostL'); + 'third-PostL; last-PostL; second-PostL; first-PostL'); var span = element.find('span'); expect(span.attr('first')).toEqual(''); @@ -1104,7 +1109,7 @@ describe('$compile', function() { expect(log).toEqual( 'iFirst-C; FLUSH; iSecond-C; iThird-C; iLast-C; ' + 'iFirst-PreL; iSecond-PreL; iThird-PreL; iLast-PreL; ' + - 'iFirst-PostL; iSecond-PostL; iThird-PostL; iLast-PostL'); + 'iLast-PostL; iThird-PostL; iSecond-PostL; iFirst-PostL'); var div = element.find('div'); expect(div.attr('i-first')).toEqual(''); @@ -1130,7 +1135,7 @@ describe('$compile', function() { expect(log).toEqual( 'first-C; FLUSH; second-C; last-C; third-C; ' + 'first-PreL; second-PreL; last-PreL; third-PreL; ' + - 'third-PostL; first-PostL; second-PostL; last-PostL'); + 'third-PostL; last-PostL; second-PostL; first-PostL'); var span = element.find('span'); expect(span.attr('first')).toEqual(''); @@ -1156,7 +1161,7 @@ describe('$compile', function() { expect(log).toEqual( 'iFirst-C; FLUSH; iSecond-C; iThird-C; iLast-C; ' + 'iFirst-PreL; iSecond-PreL; iThird-PreL; iLast-PreL; ' + - 'iFirst-PostL; iSecond-PostL; iThird-PostL; iLast-PostL'); + 'iLast-PostL; iThird-PostL; iSecond-PostL; iFirst-PostL'); var div = element.find('div'); expect(div.attr('i-first')).toEqual(''); @@ -1344,10 +1349,10 @@ describe('$compile', function() { scope: true, restrict: 'CA', compile: function() { - return function (scope, element) { + return {pre: function (scope, element) { log(scope.$id); expect(element.data('$scope')).toBe(scope); - }; + }}; } }; }); @@ -1409,9 +1414,9 @@ describe('$compile', function() { directive('log', function(log) { return { restrict: 'CA', - link: function(scope) { + link: {pre: function(scope) { log('log-' + scope.$id + '-' + scope.$parent.$id); - } + }} }; }); })); @@ -1419,7 +1424,7 @@ describe('$compile', function() { it('should allow creation of new scopes', inject(function($rootScope, $compile, log) { element = $compile('')($rootScope); - expect(log).toEqual('LOG; log-002-001; 002'); + expect(log).toEqual('002; log-002-001; LOG'); expect(element.find('span').hasClass('ng-scope')).toBe(true); })); @@ -1427,7 +1432,7 @@ describe('$compile', function() { it('should allow creation of new isolated scopes for directives', inject( function($rootScope, $compile, log) { element = $compile('')($rootScope); - expect(log).toEqual('LOG; log-002-001; 002'); + expect(log).toEqual('log-002-001; LOG; 002'); $rootScope.name = 'abc'; expect(iscope.$parent).toBe($rootScope); expect(iscope.name).toBeUndefined(); @@ -1439,7 +1444,7 @@ describe('$compile', function() { $httpBackend.expect('GET', 'tscope.html').respond('{{name}}; scopeId: {{$id}}'); element = $compile('