aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--angular-debug.js4
-rw-r--r--src/Angular.js1
-rw-r--r--src/Compiler.js35
-rw-r--r--test/ApiTest.js2
-rw-r--r--test/CompilerSpec.js2
-rw-r--r--test/ValidatorsTest.js8
-rw-r--r--test/directivesSpec.js14
7 files changed, 53 insertions, 13 deletions
diff --git a/angular-debug.js b/angular-debug.js
index 29bf63cc..d80db4df 100644
--- a/angular-debug.js
+++ b/angular-debug.js
@@ -2788,9 +2788,9 @@ foreach({
});
}
- if (state === null){
+ if (state === null && this['$invalidWidgets']){
// request in flight, mark widget invalid, but don't show it to user
- (this['$invalidWidgets']||[]).push(this.$element);
+ this['$invalidWidgets'].markInvalid(this.$element);
}
return state;
}
diff --git a/src/Angular.js b/src/Angular.js
index d60e1b85..88aab8e7 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -9,6 +9,7 @@ var consoleNode,
PRIORITY_FIRST = -99999,
PRIORITY_WATCH = -1000,
PRIORITY_LAST = 99999,
+ PRIORITY = {'FIRST': PRIORITY_FIRST, 'LAST': PRIORITY_LAST, 'WATCH':PRIORITY_WATCH},
NOOP = 'noop',
NG_EXCEPTION = 'ng-exception',
NG_VALIDATION_ERROR = 'ng-validation-error',
diff --git a/src/Compiler.js b/src/Compiler.js
index 8c95ee8e..a762b5fd 100644
--- a/src/Compiler.js
+++ b/src/Compiler.js
@@ -4,17 +4,34 @@
* bind to a new instance of elements. It also provides a list
* of child paths which contain child templates
*/
-function Template() {
+function Template(priority) {
this.paths = [];
this.children = [];
this.inits = [];
+ this.priority = priority || 0;
}
Template.prototype = {
init: function(element, scope) {
+ var inits = {};
+ this.collectInits(element, inits);
+ foreachSorted(inits, function(queue){
+ foreach(queue, function(fn){
+ fn(scope);
+ });
+ });
+ },
+
+ collectInits: function(element, inits) {
+ var queue = inits[this.priority];
+ if (!queue) {
+ inits[this.priority] = queue = [];
+ }
element = jqLite(element);
foreach(this.inits, function(fn) {
- scope.$tryEval(fn, element, element);
+ queue.push(function(scope) {
+ scope.$tryEval(fn, element, element);
+ });
});
var i,
@@ -23,7 +40,7 @@ Template.prototype = {
paths = this.paths,
length = paths.length;
for (i = 0; i < length; i++) {
- children[i].init(childNodes[paths[i]], scope);
+ children[i].collectInits(childNodes[paths[i]], inits);
}
},
@@ -78,13 +95,13 @@ Compiler.prototype = {
};
},
- templatize: function(element){
+ templatize: function(element, priority){
var self = this,
widget,
directiveFns = self.directives,
descend = true,
directives = true,
- template = new Template(),
+ template,
selfApi = {
compile: bind(self, self.compile),
comment:function(text) {return jqLite(document.createComment(text));},
@@ -93,7 +110,11 @@ Compiler.prototype = {
descend: function(value){ if(isDefined(value)) descend = value; return descend;},
directives: function(value){ if(isDefined(value)) directives = value; return directives;}
};
-
+ priority = element.attr('ng-eval-order') || priority || 0;
+ if (isString(priority)) {
+ priority = PRIORITY[uppercase(priority)] || 0;
+ }
+ template = new Template(priority);
eachAttribute(element, function(value, name){
if (!widget) {
if (widget = self.widgets['@' + name]) {
@@ -135,7 +156,7 @@ Compiler.prototype = {
// Process non text child nodes
if (descend) {
eachNode(element, function(child, i){
- template.addChild(i, self.templatize(child));
+ template.addChild(i, self.templatize(child, priority));
});
}
return template.empty() ? null : template;
diff --git a/test/ApiTest.js b/test/ApiTest.js
index 5d85987b..4035cdbb 100644
--- a/test/ApiTest.js
+++ b/test/ApiTest.js
@@ -252,5 +252,5 @@ ApiTest.prototype.testStringFromUTC = function(){
};
ApiTest.prototype.testObjectShouldHaveExtend = function(){
- assertEquals(angular.Object.extend, extend);
+ assertEquals({a:1, b:2}, angular.Object.extend({a:1}, {b:2}));
};
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index b9529e6e..fe61c520 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -72,7 +72,7 @@ describe('compiler', function(){
var scope = compile('<span hello="misko" stop="true"><span hello="adam"/></span>');
expect(log).toEqual("hello misko");
});
-
+
it('should allow creation of templates', function(){
directives.duplicate = function(expr, element){
element.replaceWith(document.createComment("marker"));
diff --git a/test/ValidatorsTest.js b/test/ValidatorsTest.js
index 17c67d38..49416ae4 100644
--- a/test/ValidatorsTest.js
+++ b/test/ValidatorsTest.js
@@ -88,11 +88,15 @@ describe('Validator:asynchronous', function(){
var value, fn;
beforeEach(function(){
+ var invalidWidgets = [];
+ invalidWidgets.markInvalid = function(element){
+ invalidWidgets.push(element);
+ };
value = null;
fn = null;
self = {
$element:jqLite('<input />'),
- $invalidWidgets:[],
+ $invalidWidgets:invalidWidgets,
$updateView: noop
};
});
@@ -125,7 +129,7 @@ describe('Validator:asynchronous', function(){
it("should not make second request to same value", function(){
asynchronous.call(self, "kai", function(v,f){value=v; fn=f;});
expect(value).toEqual('kai');
- expect(self.$invalidWidgets).toEqual([self.$element]);
+ expect(self.$invalidWidgets[0][0]).toEqual(self.$element[0]);
var spy = jasmine.createSpy();
asynchronous.call(self, "kai", spy);
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index 300602fe..76a12616 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -181,4 +181,18 @@ describe("directives", function(){
expect(scope.greet('misko')).toEqual('hello misko!');
delete window.Greeter;
});
+
+ it('should eval things according to ng-eval-order', function(){
+ var scope = compile(
+ '<div ng-init="log=\'\'">' +
+ '{{log = log + \'e\'}}' +
+ '<span ng-eval-order="first" ng-eval="log = log + \'a\'">' +
+ '{{log = log + \'b\'}}' +
+ '<span src="{{log = log + \'c\'}}"></span>' +
+ '<span bind-template="{{log = log + \'d\'}}"></span>' +
+ '</span>' +
+ '</div>');
+ expect(scope.log).toEqual('abcde');
+ });
+
});