Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 7f0eb15

Browse files
committed
fix($compile): have $observe return registration function
1 parent c4fa487 commit 7f0eb15

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/ng/compile.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@
139139
*/
140140

141141

142+
/**
143+
* @ngdoc service
144+
* @name angular.module.ng.$compileProvider
145+
* @function
146+
*
147+
* @description
148+
*
149+
*/
142150
$CompileProvider.$inject = ['$provide'];
143151
function $CompileProvider($provide) {
144152
var hasDirectives = {},
@@ -148,7 +156,21 @@ function $CompileProvider($provide) {
148156
MULTI_ROOT_TEMPLATE_ERROR = 'Template must have exactly one root element. was: ';
149157

150158

151-
this.directive = function registerDirective(name, directiveFactory) {
159+
/**
160+
* @ngdoc function
161+
* @name angular.module.ng.$compileProvider.directive
162+
* @methodOf angular.module.ng.$compileProvider
163+
* @function
164+
*
165+
* @description
166+
* Register directives with the compiler.
167+
*
168+
* @param {string} name Name of the directive in camel-case. (ie <code>ngBind</code> which will match as
169+
* <code>ng-bind</code>).
170+
* @param {function} directiveFactory An injectable directive factroy function. See {@link guide/directive} for more
171+
* info.
172+
*/
173+
this.directive = function registerDirective(name, directiveFactory) {
152174
if (isString(name)) {
153175
assertArg(directiveFactory, 'directive');
154176
if (!hasDirectives.hasOwnProperty(name)) {
@@ -295,12 +317,14 @@ function $CompileProvider($provide) {
295317
*
296318
* @param {string} key Normalized key. (ie ngAttribute) .
297319
* @param {function(*)} fn Function that will be called whenever the attribute value changes.
320+
* @returns {function(*)} the `fn` Function passed in.
298321
*/
299322
$observe: function(key, fn) {
300323
// keep only observers for interpolated attrs
301324
if (this.$$observers[key]) {
302325
this.$$observers[key].push(fn);
303326
}
327+
return fn;
304328
}
305329
};
306330

test/ng/compileSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ describe('$compile', function() {
12551255
return function(scope, elm, attr) {
12561256
observeSpy = jasmine.createSpy('$observe attr');
12571257

1258-
attr.$observe('someAttr', observeSpy);
1258+
expect(attr.$observe('someAttr', observeSpy)).toBe(observeSpy);
12591259
attrValueDuringLinking = attr.someAttr;
12601260
};
12611261
});

0 commit comments

Comments
 (0)