Improve this Doc View Source $componentController

From Get docs
< Improve this Doc ngMock‎ | serviceAngularjs/docs/1.8/api/ngmock/service/$componentcontroller

Improve this Doc View Source $componentController

  1. service in module ngMock


A service that can be used to create instances of component controllers. Useful for unit-testing.

Be aware that the controller will be instantiated and attached to the scope as specified in the component definition object. If you do not provide a $scope object in the locals param then the helper will create a new isolated scope as a child of $rootScope.

If you are using $element or $attrs in the controller, make sure to provide them as locals. The $element must be a jqLite-wrapped DOM element, and $attrs should be an object that has all properties / functions that you are using in the controller. If this is getting too complex, you should compile the component instead and access the component's controller via the controller function.

See also the section on unit-testing component controllers in the guide.


$componentController(componentName, locals, [bindings], [ident]);


Param Type Details
componentName string the name of the component whose controller we want to instantiate
locals Object Injection locals for Controller.



Object Properties to add to the controller before invoking the constructor. This is used to simulate the bindToController feature and simplify certain kinds of tests.



string Override the property name to use when attaching the controller to the scope.


Object Instance of requested controller.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.$componentController