aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThibault Leruitte2013-02-26 11:14:27 +0100
committerIgor Minar2013-02-28 17:27:27 -0800
commitfe8d893b839e9b14e3e55a3a0523cc1e6355bdd5 (patch)
treeea3442e28bf4fdfd476c150255257d5a9641a011 /src
parenteb53423a41136fcda0c5e711f2d104952080354b (diff)
downloadangular.js-fe8d893b839e9b14e3e55a3a0523cc1e6355bdd5.tar.bz2
feat($compile): allow directives to modify interpolated attributes
A directive can now set/update/remove attribute values even those containing interpolation during the compile phase and have the new value be picked up during the compilation. For example in template: <div replace-directive some-attr-or-directive="{{originalInterpolationValue}}"></div> the replace-directive can now replace the value of some-attr-or-directive during compilation which produces this intermitent template: <div replace-directive some-attr-or-directive="{{replacedInterpolationValue}}"></div> or even <div replace-directive some-attr-or-directive="replacedStaticValue"></div> as well as <div replace-directive some-attr-or-directive></div>
Diffstat (limited to 'src')
-rw-r--r--src/ng/compile.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index c04d3871..6606dc6c 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -1102,11 +1102,13 @@ function $CompileProvider($provide) {
compile: valueFn(function attrInterpolateLinkFn(scope, element, attr) {
var $$observers = (attr.$$observers || (attr.$$observers = {}));
- 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 need to interpolate again, in case the attribute value has been updated
+ // (e.g. by another directive's compile function)
+ interpolateFn = $interpolate(attr[name], true);
+
+ // if attribute was updated so that there is no interpolation going on we don't want to
+ // register any observers
+ if (!interpolateFn) return;
attr[name] = interpolateFn(scope);
($$observers[name] || ($$observers[name] = [])).$$inter = true;
@@ -1203,7 +1205,7 @@ function directiveNormalize(name) {
* @param {string} name Normalized element attribute name of the property to modify. The name is
* revers translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
* property to the original name.
- * @param {string} value Value to set the attribute to.
+ * @param {string} value Value to set the attribute to. The value can be an interpolated string.
*/