aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/directive/booleanAttrDirs.js73
-rw-r--r--src/service/compiler.js66
2 files changed, 70 insertions, 69 deletions
diff --git a/src/directive/booleanAttrDirs.js b/src/directive/booleanAttrDirs.js
index 10c6eee8..7da52db0 100644
--- a/src/directive/booleanAttrDirs.js
+++ b/src/directive/booleanAttrDirs.js
@@ -130,7 +130,7 @@
<doc:example>
<doc:source>
Click me to toggle: <input type="checkbox" ng-model="checked"><br/>
- <button ng-model="button" ng-disabled="{{checked}}">Button</button>
+ <button ng-model="button" ng-disabled="checked">Button</button>
</doc:source>
<doc:scenario>
it('should toggle button', function() {
@@ -142,7 +142,7 @@
</doc:example>
*
* @element INPUT
- * @param {template} ng-disabled any string which can contain '{{}}' markup.
+ * @param {string} expression Angular expression that will be evaluated.
*/
@@ -160,7 +160,7 @@
<doc:example>
<doc:source>
Check me to check both: <input type="checkbox" ng-model="master"><br/>
- <input id="checkSlave" type="checkbox" ng-checked="{{master}}">
+ <input id="checkSlave" type="checkbox" ng-checked="master">
</doc:source>
<doc:scenario>
it('should check both checkBoxes', function() {
@@ -172,7 +172,7 @@
</doc:example>
*
* @element INPUT
- * @param {template} ng-checked any string which can contain '{{}}' markup.
+ * @param {string} expression Angular expression that will be evaluated.
*/
@@ -191,7 +191,7 @@
<doc:example>
<doc:source>
Check me check multiple: <input type="checkbox" ng-model="checked"><br/>
- <select id="select" ng-multiple="{{checked}}">
+ <select id="select" ng-multiple="checked">
<option>Misko</option>
<option>Igor</option>
<option>Vojta</option>
@@ -208,7 +208,7 @@
</doc:example>
*
* @element SELECT
- * @param {template} ng-multiple any string which can contain '{{}}' markup.
+ * @param {string} expression Angular expression that will be evaluated.
*/
@@ -226,7 +226,7 @@
<doc:example>
<doc:source>
Check me to make text readonly: <input type="checkbox" ng-model="checked"><br/>
- <input type="text" ng-readonly="{{checked}}" value="I'm Angular"/>
+ <input type="text" ng-readonly="checked" value="I'm Angular"/>
</doc:source>
<doc:scenario>
it('should toggle readonly attr', function() {
@@ -238,7 +238,7 @@
</doc:example>
*
* @element INPUT
- * @param {template} ng-readonly any string which can contain '{{}}' markup.
+ * @param {string} expression Angular expression that will be evaluated.
*/
@@ -255,35 +255,60 @@
* @example
<doc:example>
<doc:source>
- Check me to select: <input type="checkbox" ng-model="checked"><br/>
+ Check me to select: <input type="checkbox" ng-model="selected"><br/>
<select>
<option>Hello!</option>
- <option id="greet" ng-selected="{{checked}}">Greetings!</option>
+ <option id="greet" ng-selected="selected">Greetings!</option>
</select>
</doc:source>
<doc:scenario>
it('should select Greetings!', function() {
expect(element('.doc-example-live #greet').prop('selected')).toBeFalsy();
- input('checked').check();
+ input('selected').check();
expect(element('.doc-example-live #greet').prop('selected')).toBeTruthy();
});
</doc:scenario>
</doc:example>
+ *
* @element OPTION
- * @param {template} ng-selected any string which can contain '{{}}' markup.
+ * @param {string} expression Angular expression that will be evaluated.
*/
-
-function ngAttributeAliasDirective(propName, attrName) {
- ngAttributeAliasDirectives[directiveNormalize('ng-' + attrName)] = valueFn(
- function(scope, element, attr) {
- attr.$observe(directiveNormalize('ng-' + attrName), function(value) {
- attr.$set(attrName, value);
- });
- }
- );
-}
var ngAttributeAliasDirectives = {};
-forEach(BOOLEAN_ATTR, ngAttributeAliasDirective);
-ngAttributeAliasDirective(null, 'src');
+
+
+// boolean attrs are evaluated
+forEach(BOOLEAN_ATTR, function(propName, attrName) {
+ var normalized = directiveNormalize('ng-' + attrName);
+ ngAttributeAliasDirectives[normalized] = function() {
+ return {
+ compile: function(tpl, attr) {
+ attr.$observers[attrName] = [];
+ return function(scope, element, attr) {
+ scope.$watch(attr[normalized], function(value) {
+ attr.$set(attrName, value);
+ });
+ };
+ }
+ };
+ };
+});
+
+
+// ng-src, ng-href are interpolated
+forEach(['src', 'href'], function(attrName) {
+ var normalized = directiveNormalize('ng-' + attrName);
+ ngAttributeAliasDirectives[normalized] = function() {
+ return {
+ compile: function(tpl, attr) {
+ attr.$observers[attrName] = [];
+ return function(scope, element, attr) {
+ attr.$observe(normalized, function(value) {
+ attr.$set(attrName, value);
+ });
+ };
+ }
+ };
+ };
+});
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;