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”>

studentController using ng-controller directive.Next step we’ll define the studentController as follows:

function studentController($scope) {
$scope.student = {
firstName: “Priya”,
lastName: “Mary”,
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + ” ” + studentObject.lastName;

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>
You are entering: {{student.fullName()}}

AngularJs Example



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