From 7f0eb1516165fcb73f1c9953018b7c9b70acfae1 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Thu, 3 May 2012 16:30:36 -0700
Subject: fix($compile): have $observe return registration function
---
src/ng/compile.js | 26 +++++++++++++++++++++++++-
test/ng/compileSpec.js | 2 +-
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 6a6ffc3c..8a29a6c6 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -139,6 +139,14 @@
*/
+/**
+ * @ngdoc service
+ * @name angular.module.ng.$compileProvider
+ * @function
+ *
+ * @description
+ *
+ */
$CompileProvider.$inject = ['$provide'];
function $CompileProvider($provide) {
var hasDirectives = {},
@@ -148,7 +156,21 @@ function $CompileProvider($provide) {
MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: ';
- this.directive = function registerDirective(name, directiveFactory) {
+ /**
+ * @ngdoc function
+ * @name angular.module.ng.$compileProvider.directive
+ * @methodOf angular.module.ng.$compileProvider
+ * @function
+ *
+ * @description
+ * Register directives with the compiler.
+ *
+ * @param {string} name Name of the directive in camel-case. (ie ngBind which will match as
+ * ng-bind).
+ * @param {function} directiveFactory An injectable directive factroy function. See {@link guide/directive} for more
+ * info.
+ */
+ this.directive = function registerDirective(name, directiveFactory) {
if (isString(name)) {
assertArg(directiveFactory, 'directive');
if (!hasDirectives.hasOwnProperty(name)) {
@@ -295,12 +317,14 @@ function $CompileProvider($provide) {
*
* @param {string} key Normalized key. (ie ngAttribute) .
* @param {function(*)} fn Function that will be called whenever the attribute value changes.
+ * @returns {function(*)} the `fn` Function passed in.
*/
$observe: function(key, fn) {
// keep only observers for interpolated attrs
if (this.$$observers[key]) {
this.$$observers[key].push(fn);
}
+ return fn;
}
};
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index c5592816..86ba3ade 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -1255,7 +1255,7 @@ describe('$compile', function() {
return function(scope, elm, attr) {
observeSpy = jasmine.createSpy('$observe attr');
- attr.$observe('someAttr', observeSpy);
+ expect(attr.$observe('someAttr', observeSpy)).toBe(observeSpy);
attrValueDuringLinking = attr.someAttr;
};
});
--
cgit v1.2.3