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

Commit 9881e77

Browse files
refactor($componentController): don't return an object from the provider constructor function
Closes #13969 Closes #13977
1 parent 17ba2a6 commit 9881e77

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

src/ngMock/angular-mocks.js

+21-23
Original file line numberDiff line numberDiff line change
@@ -2182,29 +2182,27 @@ angular.mock.$ControllerDecorator = ['$delegate', function($delegate) {
21822182
* @return {Object} Instance of requested controller.
21832183
*/
21842184
angular.mock.$ComponentControllerProvider = ['$compileProvider', function($compileProvider) {
2185-
return {
2186-
$get: ['$controller','$injector', function($controller,$injector) {
2187-
return function $componentController(componentName, locals, bindings, ident) {
2188-
// get all directives associated to the component name
2189-
var directives = $injector.get(componentName + 'Directive');
2190-
// look for those directives that are components
2191-
var candidateDirectives = directives.filter(function(directiveInfo) {
2192-
// components have controller, controllerAs and restrict:'E'
2193-
return directiveInfo.controller && directiveInfo.controllerAs && directiveInfo.restrict === 'E';
2194-
});
2195-
// check if valid directives found
2196-
if (candidateDirectives.length === 0) {
2197-
throw new Error('No component found');
2198-
}
2199-
if (candidateDirectives.length > 1) {
2200-
throw new Error('Too many components found');
2201-
}
2202-
// get the info of the component
2203-
var directiveInfo = candidateDirectives[0];
2204-
return $controller(directiveInfo.controller, locals, bindings, ident || directiveInfo.controllerAs);
2205-
};
2206-
}]
2207-
};
2185+
this.$get = ['$controller','$injector', function($controller,$injector) {
2186+
return function $componentController(componentName, locals, bindings, ident) {
2187+
// get all directives associated to the component name
2188+
var directives = $injector.get(componentName + 'Directive');
2189+
// look for those directives that are components
2190+
var candidateDirectives = directives.filter(function(directiveInfo) {
2191+
// components have controller, controllerAs and restrict:'E'
2192+
return directiveInfo.controller && directiveInfo.controllerAs && directiveInfo.restrict === 'E';
2193+
});
2194+
// check if valid directives found
2195+
if (candidateDirectives.length === 0) {
2196+
throw new Error('No component found');
2197+
}
2198+
if (candidateDirectives.length > 1) {
2199+
throw new Error('Too many components found');
2200+
}
2201+
// get the info of the component
2202+
var directiveInfo = candidateDirectives[0];
2203+
return $controller(directiveInfo.controller, locals, bindings, ident || directiveInfo.controllerAs);
2204+
};
2205+
}];
22082206
}];
22092207

22102208

0 commit comments

Comments
 (0)