Skip to content

Commit 6fe7ce5

Browse files
committed
wip: module.component helper
Closes angular#10007
1 parent 7dcfe5e commit 6fe7ce5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/loader.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,44 @@ function setupModuleLoader(window) {
282282
*/
283283
directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),
284284

285+
/**
286+
* @ngdoc method
287+
* @name angular.Module#component
288+
* @module ng
289+
* @param {string} name A directive name
290+
* @param {Object} options Component definition object
291+
* @description
292+
* TODO...
293+
*/
294+
component: function(name, options) {
295+
config(['$compileProvider', function ($compileProvider) {
296+
var controller = options.controller || function () {};
297+
298+
['$onActivate', '$onDeactivate', '$onReuse', '$canReuse', '$canDeactivate'].forEach(function (hookName) {
299+
if (options[hookName]) {
300+
controller.prototype[hookName] = options[hookName];
301+
}
302+
});
303+
304+
function factory() {
305+
return {
306+
template: options.template || '',
307+
controllerAs: name,
308+
controller: controller
309+
};
310+
}
311+
312+
if (options.$canActivate) {
313+
factory.$canActivate = options.$canActivate;
314+
}
315+
if (options.$routeConfig) {
316+
factory.$routeConfig = options.$routeConfig;
317+
}
318+
$compileProvider.directive(name, factory);
319+
}]);
320+
return moduleInstance;
321+
},
322+
285323
/**
286324
* @ngdoc method
287325
* @name angular.Module#config

0 commit comments

Comments
 (0)