top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is Controller in AngularJS?

0 votes
270 views
What is Controller in AngularJS?
posted Nov 1, 2017 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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>
answer Nov 1, 2017 by Shivaranjini
...