The controller definesthe actual behavior of your app. It contains business logic for the view and connects
the model to view with the help of $scope. A controller is associated with a HTML element with the ng-controller
directive.
Creating Controller
<script type="text/javascript">
//defining main controller
app.controller('mainController', function ($scope) {
//defining book viewmodel
$scope.book =
{
id: 1,
name: 'AngularJS Interview Questions and Answers',
author: 'Shailendra Chauhan',
};
});
</script>
Using Controller
<div ng-controller="mainController">
Id: <span ng-bind="book.id"></span>
<br />
Name:<input type="text" ng-model="book.name" />
<br />
Author: <input type="text" ng-model="book.author" />
</div>