Controllers are one of the core units of any Angular application. Controllers are used to create a small part of a module that requires its own scope. Each module can have many controllers. Controllers should be small and focused on one task.
Each controller should really only worry about the data and any events that modify that data. This means a controller should not modify the DOM, change output or input, or share state with another controller. Each of these should use the Angular solution, directives or filters, and services, respectively.
Controllers are created from a module reference, so they are tied to modules. Here is an example of creating a simple controller:
firstModule.controller('SimpleController', ['$scope', function ($scope) { $scope.hey = "HEY!"; console.log($scope); }]);
This module can then be attached to a DOM element with ngController
:
<div ng-controller="SimpleController"> {{ hey }} </div>