AngularJS application mainly relies on controllers to control the flow of data in the application. A controller is defined using ng-controller directive. A controller is a JavaScript object containing attributes/properties and functions. Each controller accepts $scope as a parameter which refers to the application/module that controller is to control.
<div ng-app = "" ng-controller = "empController">
... </div> <script> function empController($scope) { $scope.emp = { firstName: "aarif", lastName: "mohammad", fullName: function() { var empObject; empObject= $scope.emp; return empObject.firstName + " " + empObject.lastName; } }; } </script> |