aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisko Hevery2012-04-28 22:23:38 -0700
committerMisko Hevery2012-05-04 15:50:37 -0700
commitcef3535c16d5b7825f797adc6705d61dad759796 (patch)
tree15b5a8f83bf530bfe5dcaefa7bac5661daf3dfdb
parentfbb499e0a82ba9b816916f275d786775aa6cf467 (diff)
downloadangular.js-cef3535c16d5b7825f797adc6705d61dad759796.tar.bz2
chore(controller): allow setting map of controllers
-rw-r--r--src/ng/controller.js6
-rw-r--r--test/ng/controllerSpec.js22
2 files changed, 25 insertions, 3 deletions
diff --git a/src/ng/controller.js b/src/ng/controller.js
index fa90f8cd..67f70aad 100644
--- a/src/ng/controller.js
+++ b/src/ng/controller.js
@@ -23,7 +23,11 @@ function $ControllerProvider() {
* annotations in the array notation).
*/
this.register = function(name, constructor) {
- controllers[name] = constructor;
+ if (isObject(name)) {
+ extend(controllers, name)
+ } else {
+ controllers[name] = constructor;
+ }
};
diff --git a/test/ng/controllerSpec.js b/test/ng/controllerSpec.js
index 91389013..2abcace9 100644
--- a/test/ng/controllerSpec.js
+++ b/test/ng/controllerSpec.js
@@ -17,8 +17,8 @@ describe('$controller', function() {
it('should allow registration of controllers', function() {
var FooCtrl = function($scope) { $scope.foo = 'bar' },
- scope = {},
- ctrl;
+ scope = {},
+ ctrl;
$controllerProvider.register('FooCtrl', FooCtrl);
ctrl = $controller('FooCtrl', {$scope: scope});
@@ -28,6 +28,24 @@ describe('$controller', function() {
});
+ it('should allow registration of map of controllers', function() {
+ var FooCtrl = function($scope) { $scope.foo = 'foo' },
+ BarCtrl = function($scope) { $scope.bar = 'bar' },
+ scope = {},
+ ctrl;
+
+ $controllerProvider.register({FooCtrl: FooCtrl, BarCtrl: BarCtrl} );
+
+ ctrl = $controller('FooCtrl', {$scope: scope});
+ expect(scope.foo).toBe('foo');
+ expect(ctrl instanceof FooCtrl).toBe(true);
+
+ ctrl = $controller('BarCtrl', {$scope: scope});
+ expect(scope.bar).toBe('bar');
+ expect(ctrl instanceof BarCtrl).toBe(true);
+ });
+
+
it('should allow registration of controllers annotated with arrays', function() {
var FooCtrl = function($scope) { $scope.foo = 'bar' },
scope = {},