mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 07:50:22 +00:00
chore(controller): allow setting map of controllers
This commit is contained in:
parent
fbb499e0a8
commit
cef3535c16
2 changed files with 25 additions and 3 deletions
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = {},
|
||||
|
|
|
|||
Loading…
Reference in a new issue