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

Commit

Permalink
fix($compile): have $observe return registration function
Browse files Browse the repository at this point in the history
  • Loading branch information
mhevery committed May 4, 2012
1 parent c4fa487 commit 7f0eb15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@
*/


/**
* @ngdoc service
* @name angular.module.ng.$compileProvider
* @function
*
* @description
*
*/
$CompileProvider.$inject = ['$provide'];
function $CompileProvider($provide) {
var hasDirectives = {},
Expand All @@ -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 <code>ngBind</code> which will match as
* <code>ng-bind</code>).
* @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)) {
Expand Down Expand Up @@ -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;
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
});
Expand Down

0 comments on commit 7f0eb15

Please sign in to comment.