aboutsummaryrefslogtreecommitdiffstats
path: root/src/ng/compile.js
diff options
context:
space:
mode:
authorCaio Cunha2014-01-02 23:02:12 -0500
committerIgor Minar2014-03-18 13:44:16 -0700
commit299b220f5e05e1d4e26bfd58d0b2fd7329ca76b1 (patch)
tree3cfa2c8a257742ff20f24f0225a9d8abf100fdab /src/ng/compile.js
parent78057a945ef84cbb05f9417fe884cb8c28e67b44 (diff)
downloadangular.js-299b220f5e05e1d4e26bfd58d0b2fd7329ca76b1.tar.bz2
feat($compile): add support for $observer deregistration
In order to make the behavior compatible with $rootScope.$watch and $rootScope.$on methods, and make it possible to deregister an attribute observer, Attributes.$observe method now returns a deregistration function instead of the observer itself. BREAKING CHANGE: calling attr.$observe no longer returns the observer function, but a deregistration function instead. To migrate the code follow the example below: Before: ``` directive('directiveName', function() { return { link: function(scope, elm, attr) { var observer = attr.$observe('someAttr', function(value) { console.log(value); }); } }; }); ``` After: ``` directive('directiveName', function() { return { link: function(scope, elm, attr) { var observer = function(value) { console.log(value); }; attr.$observe('someAttr', observer); } }; }); ``` Closes #5609
Diffstat (limited to 'src/ng/compile.js')
-rw-r--r--src/ng/compile.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index c7cd08bc..8cc518d5 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -775,7 +775,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
* @param {function(interpolatedValue)} fn Function that will be called whenever
the interpolated value of the attribute changes.
* See the {@link guide/directive#Attributes Directives} guide for more info.
- * @returns {function()} the `fn` parameter.
+ * @returns {function()} Returns a deregistration function for this observer.
*/
$observe: function(key, fn) {
var attrs = this,
@@ -789,7 +789,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
fn(attrs[key]);
}
});
- return fn;
+
+ return function() {
+ arrayRemove(listeners, fn);
+ };
}
};