AngularJS controllers tp control the flow of data in AngularJS applications.The ng-controller directive is used for defined controller.Its regular javascript object containing attributes/properties and functions.
<div ng-app=”” ng-controller=”studentController”>
…
</div>
studentController using ng-controller directive.Next step we’ll define the studentController as follows:
<script>
function studentController($scope) {
$scope.student = {
firstName: “Priya”,
lastName: “Mary”,
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + ” ” + studentObject.lastName;
}
};
}
</script>
studentController’s student property using ng-model or using expressions as:
Enter first name: <input type=”text” ng-model=”student.firstName”> <br>
Enter last name: <input type=”text” ng-model=”student.lastName”> <br>
<br>
You are entering: {{student.fullName()}}
AngularJs Example
Angular JS Controller AngularJS Sample Application
Enter first name:
Enter last name:
You are entering: {{student.fullName()}}
OUTPUT