The Relationship Between Scopes and Controllers

Controllers are pieces of code that are intended to provide business logic by augmenting scope. You create controllers by using the controller() method on the Model object of an application. This function registers a controller as a provider in the module, but it does not create an instance of the controller. That occurs when the ng-controller directive is linked in an AngularJS template.

The controller() method accepts the controller name as the first parameter and an array of dependencies as the second parameter. For example, the following code defines a controller that uses dependency injection to access a value provider named start:

angular.module('myApp', []). ...

Get Learning AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.