aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMisko Hevery2010-07-15 13:13:21 -0700
committerMisko Hevery2010-07-15 13:13:21 -0700
commit9abd10e7b8a34b9dcd1a6af5ff37f57bd27cf920 (patch)
tree1dac2305341b58cb595ebc4b71ea5debf121e37b /src
parent09e2295975b5bb8dfc067303fee86a9f2ebb433d (diff)
downloadangular.js-9abd10e7b8a34b9dcd1a6af5ff37f57bd27cf920.tar.bz2
proper handlig of $element in filters
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js4
-rw-r--r--src/directives.js18
-rw-r--r--src/widgets.js3
3 files changed, 16 insertions, 9 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 2b26c88d..07e9096b 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -78,6 +78,10 @@ function extend(dst) {
return dst;
}
+function inherit(parent, extra) {
+ return extend(new (extend(function(){}, {prototype:parent}))(), extra);
+};
+
function noop() {}
function identity($) {return $;}
function extensionMap(angular, name) {
diff --git a/src/directives.js b/src/directives.js
index bcc427e8..b57e5ecd 100644
--- a/src/directives.js
+++ b/src/directives.js
@@ -26,12 +26,13 @@ angularDirective("ng:bind", function(expression){
return function(element) {
var lastValue = noop, lastError = noop;
this.$onEval(function() {
- var error,
- value = this.$tryEval(expression, function(e){
- error = toJson(e);
- }),
- isHtml,
- isDomElement;
+ var error, value, isHtml, isDomElement,
+ oldElement = this.hasOwnProperty('$element') ? this.$element : undefined;
+ this.$element = element;
+ value = this.$tryEval(expression, function(e){
+ error = toJson(e);
+ });
+ this.$element = oldElement;
if (lastValue === value && lastError == error) return;
isHtml = value instanceof HTML,
isDomElement = isElement(value);
@@ -74,7 +75,9 @@ function compileBindTemplate(template){
});
});
bindTemplateCache[template] = fn = function(element){
- var parts = [], self = this;
+ var parts = [], self = this,
+ oldElement = this.hasOwnProperty('$element') ? this.$element : undefined;
+ this.$element = element;
for ( var i = 0; i < bindings.length; i++) {
var value = bindings[i].call(self, element);
if (isElement(value))
@@ -83,6 +86,7 @@ function compileBindTemplate(template){
value = toJson(value, true);
parts.push(value);
};
+ this.$element = oldElement;
return parts.join('');
};
}
diff --git a/src/widgets.js b/src/widgets.js
index 0b77dbf4..7bd51c8c 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -83,8 +83,7 @@ function valueAccessor(scope, element) {
elementError(element, NG_VALIDATION_ERROR, null);
invalidWidgets.markValid(element);
} else {
- var error,
- validateScope = extend(new (extend(function(){}, {prototype:scope}))(), {$element:element});
+ var error, validateScope = inherit(scope, {$element:element});
error = required && !value ?
'Required' :
(value ? validator(validateScope, value) : null);