Skip to content

Commit cef3535

Browse files
committed
chore(controller): allow setting map of controllers
1 parent fbb499e commit cef3535

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/ng/controller.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ function $ControllerProvider() {
2323
* annotations in the array notation).
2424
*/
2525
this.register = function(name, constructor) {
26-
controllers[name] = constructor;
26+
if (isObject(name)) {
27+
extend(controllers, name)
28+
} else {
29+
controllers[name] = constructor;
30+
}
2731
};
2832

2933

test/ng/controllerSpec.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ describe('$controller', function() {
1717

1818
it('should allow registration of controllers', function() {
1919
var FooCtrl = function($scope) { $scope.foo = 'bar' },
20-
scope = {},
21-
ctrl;
20+
scope = {},
21+
ctrl;
2222

2323
$controllerProvider.register('FooCtrl', FooCtrl);
2424
ctrl = $controller('FooCtrl', {$scope: scope});
@@ -28,6 +28,24 @@ describe('$controller', function() {
2828
});
2929

3030

31+
it('should allow registration of map of controllers', function() {
32+
var FooCtrl = function($scope) { $scope.foo = 'foo' },
33+
BarCtrl = function($scope) { $scope.bar = 'bar' },
34+
scope = {},
35+
ctrl;
36+
37+
$controllerProvider.register({FooCtrl: FooCtrl, BarCtrl: BarCtrl} );
38+
39+
ctrl = $controller('FooCtrl', {$scope: scope});
40+
expect(scope.foo).toBe('foo');
41+
expect(ctrl instanceof FooCtrl).toBe(true);
42+
43+
ctrl = $controller('BarCtrl', {$scope: scope});
44+
expect(scope.bar).toBe('bar');
45+
expect(ctrl instanceof BarCtrl).toBe(true);
46+
});
47+
48+
3149
it('should allow registration of controllers annotated with arrays', function() {
3250
var FooCtrl = function($scope) { $scope.foo = 'bar' },
3351
scope = {},

0 commit comments

Comments
 (0)