aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/compiler.js
diff options
context:
space:
mode:
authorVojta Jina2012-03-23 15:53:04 -0700
committerVojta Jina2012-03-26 21:14:09 -0700
commita08cbc02e78e789a66e9af771c410e8ad1646e25 (patch)
treebc7081b11d6d1ed4cd5bde3a9e059e5c964e75a8 /src/service/compiler.js
parent55027132f3d57e5dcf94683e6e6bd7b0aae0087d (diff)
downloadangular.js-a08cbc02e78e789a66e9af771c410e8ad1646e25.tar.bz2
feat($compile): do not interpolate boolean attributes, rather evaluate them
So that we can have non string values, e.g. ng-value="true" for radio inputs Breaks boolean attrs are evaluated rather than interpolated To migrate your code, change: <input ng-disabled="{{someBooleanVariable}}"> to: <input ng-disabled="someBooleanVariabla"> Affected directives: * ng-multiple * ng-selected * ng-checked * ng-disabled * ng-readonly * ng-required
Diffstat (limited to 'src/service/compiler.js')
-rw-r--r--src/service/compiler.js66
1 files changed, 21 insertions, 45 deletions
diff --git a/src/service/compiler.js b/src/service/compiler.js
index 8ddf77ae..a22c5d66 100644
--- a/src/service/compiler.js
+++ b/src/service/compiler.js
@@ -128,13 +128,7 @@ function $CompileProvider($provide) {
COMMENT_DIRECTIVE_REGEXP = /^\s*directive\:\s*([\d\w\-_]+)\s+(.*)$/,
CLASS_DIRECTIVE_REGEXP = /(([\d\w\-_]+)(?:\:([^;]+))?;?)/,
CONTENT_REGEXP = /\<\<content\>\>/i,
- HAS_ROOT_ELEMENT = /^\<[\s\S]*\>$/,
- SIDE_EFFECT_ATTRS = {};
-
- forEach('src,href,multiple,selected,checked,disabled,readonly,required'.split(','), function(name) {
- SIDE_EFFECT_ATTRS[name] = name;
- SIDE_EFFECT_ATTRS[directiveNormalize('ng_' + name)] = name;
- });
+ HAS_ROOT_ELEMENT = /^\<[\s\S]*\>$/;
this.directive = function registerDirective(name, directiveFactory) {
@@ -861,44 +855,29 @@ function $CompileProvider($provide) {
function addAttrInterpolateDirective(node, directives, value, name) {
- var interpolateFn = $interpolate(value, true),
- realName = SIDE_EFFECT_ATTRS[name],
- specialAttrDir = (realName && (realName !== name));
-
- realName = realName || name;
+ var interpolateFn = $interpolate(value, true);
- if (specialAttrDir && isBooleanAttr(node, name)) {
- value = true;
- }
- // no interpolation found and we are not a side-effect attr -> ignore
- if (!interpolateFn && !specialAttrDir) {
- return;
- }
+ // no interpolation found -> ignore
+ if (!interpolateFn) return;
directives.push({
priority: 100,
- compile: function(element, attr) {
- if (interpolateFn) {
- return function(scope, element, attr) {
- if (name === 'class') {
- // we need to interpolate classes again, in the case the element was replaced
- // and therefore the two class attrs got merged - we want to interpolate the result
- interpolateFn = $interpolate(attr[name], true);
- }
-
- // we define observers array only for interpolated attrs
- // and ignore observers for non interpolated attrs to save some memory
- attr.$observers[realName] = [];
- attr[realName] = undefined;
- scope.$watch(interpolateFn, function(value) {
- attr.$set(realName, value);
- });
- };
- } else {
- attr.$set(realName, value);
+ compile: valueFn(function(scope, element, attr) {
+ if (name === 'class') {
+ // we need to interpolate classes again, in the case the element was replaced
+ // and therefore the two class attrs got merged - we want to interpolate the result
+ interpolateFn = $interpolate(attr[name], true);
}
- }
+
+ // we define observers array only for interpolated attrs
+ // and ignore observers for non interpolated attrs to save some memory
+ attr.$observers[name] = [];
+ attr[name] = undefined;
+ scope.$watch(interpolateFn, function(value) {
+ attr.$set(name, value);
+ });
+ })
});
}
@@ -945,15 +924,12 @@ function $CompileProvider($provide) {
var booleanKey = isBooleanAttr(this.$element[0], key.toLowerCase());
if (booleanKey) {
- value = toBoolean(value);
this.$element.prop(key, value);
- this[key] = value;
- attrName = key = booleanKey;
- value = value ? booleanKey : undefined;
- } else {
- this[key] = value;
+ attrName = booleanKey;
}
+ this[key] = value;
+
// translate normalized key to actual key
if (attrName) {
this.$attr[key] = attrName;