AngularJS Controllers

1.What is Angular Js Controllers?

Angular Js Applications are controlled by the controller to control the flow of data in the application.

A controller is a javascript object containing a attributes/properties and functions.

Each controller accepts $scope as a parameter which refers to application/module that controller to control.

The ng-controller directive defines the application controller.

 

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/
ajax/libs/angularjs/1.4.5/angular.min.js"></script>
</head>
<body>
<div ng-app="myFirstApp" ng-controller="myController">
First Name: <input type="text" ng-model="fName"><br>
Last Name: <input type="text" ng-model="lName"><br>
<br> Name: {{fName + " " + lName}}
</div>
<script>
var myFirstApp= angular.module('myFirstApp', []);
myFirstApp.controller('myController', function($scope) { $scope.fName = 'Abc'; $scope.lName = "Learn";
});
</script>
</body>
</html>