Home / Web Development / Angular Js / AngularJS Controllers

AngularJS Controllers

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




OUTPUT

angularjs3

Loading Facebook Comments ...
Social Media Auto Publish Powered By : XYZScripts.com