Improve this Doc View Source $controller

  1. $controllerProvider
  2. service in module ng

Overview

$controller service is responsible for instantiating controllers.

It's just a simple call to $injector, but extracted into a service, so that one can override this service with BC version.

Dependencies

Usage

$controller(constructor, locals);

Arguments

Param Type Details
constructor function()string

If called with a function then it's considered to be the controller constructor function. Otherwise it's considered to be a string which is used to retrieve the controller constructor using the following steps:

  • check if a controller with given name is registered via $controllerProvider
  • check if evaluating the string on the current scope returns a constructor

    The string can use the controller as property syntax, where the controller instance is published as the specified property on the scope; the scope must be injected into locals param for this to work correctly.

locals Object

Injection locals for Controller.

Returns

Object

Instance of given controller.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.
https://code.angularjs.org/1.8.2/docs/api/ng/service/$controller