aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2010-07-15 13:35:00 -0700
committerMisko Hevery2010-07-15 13:35:00 -0700
commit1de82283dbf1bed2fc04700584dc1123b1e159fe (patch)
tree1c90427efab9838c40e44ece76c641dbf2dcccab
parent9abd10e7b8a34b9dcd1a6af5ff37f57bd27cf920 (diff)
downloadangular.js-1de82283dbf1bed2fc04700584dc1123b1e159fe.tar.bz2
proper handlig of $element in filters
-rw-r--r--src/directives.js6
-rw-r--r--test/directivesSpec.js9
2 files changed, 9 insertions, 6 deletions
diff --git a/src/directives.js b/src/directives.js
index b57e5ecd..04831131 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -76,8 +76,8 @@ function compileBindTemplate(template){
});
bindTemplateCache[template] = fn = function(element){
var parts = [], self = this,
- oldElement = this.hasOwnProperty('$element') ? this.$element : undefined;
- this.$element = element;
+ oldElement = this.hasOwnProperty('$element') ? self.$element : undefined;
+ self.$element = element;
for ( var i = 0; i < bindings.length; i++) {
var value = bindings[i].call(self, element);
if (isElement(value))
@@ -86,7 +86,7 @@ function compileBindTemplate(template){
value = toJson(value, true);
parts.push(value);
};
- this.$element = oldElement;
+ self.$element = oldElement;
return parts.join('');
};
}
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index b6ccf764..fb1e868a 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -73,11 +73,14 @@ describe("directives", function(){
});
it('should have $element set to current bind element', function(){
- angularFilter.myFilter = function(){
- this.$element.text('HELLO');
+ var innerText;
+ angularFilter.myFilter = function(text){
+ innerText = this.$element.text();
+ return text;
};
- var scope = compile('<div>before<div ng:bind-template="{{0|myFilter}}"></div>after</div>');
+ var scope = compile('<div>before<div ng:bind-template="{{\'HELLO\'|myFilter}}">INNER</div>after</div>');
expect(scope.$element.text()).toEqual("beforeHELLOafter");
+ expect(innerText).toEqual('INNER');
});
});