Controllers control a certain scope.

A scope links the controller with a view.

A controller has access to all the models in that scope and can manipulate them with JavaScript.

A scope holds model data.

 

Controllers...

- Set up the initial state of a scope

- Add behaviour to the scope object

 

html:


<div ng-controller="MyController">

 Your name:

 <input type="text" ng-model="username">

 <h1>{{username}}</h1>

</div>

 

 

Foobar.js

var MyController = function($scope) {
 $scope.username = 'World';
 }