A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Why do We Use of Controller in AngularJs ?

Use of Controller:

·       It is an object of JS that contains all the logic of web applications.
·       It is a part of Angular Module.

·       It works as send or receive the data.

Example:
<!DOCTYPE html>
<html>
<script src="angular.min.js"></script>

<script>
var mymodule=angular.module("mymodule",[]);
mymodule.controller("mycont",function(){
this.name="HeeraBabu";
});
</script>

<body>
<div ng-app="mymodule" ng-controller="mycont as obj">
  <h1>Hello {{obj.name}}</h1>
</div>

</body>
</html>
·       Here "mycont" is the name of controller function() it contains the definition of the controller.
·       "mycont as obj" here obj is an instance or object of a controller by this object we can access data from a function.
·       ng-controller it is a directive as like ng-app but ng-controller always inside the ng-app directive.
·       ng-controller it is a built-in directive which provides functionality to our applications.
·       We also can use the ng-controller with the help of ($scope).
·       Data stores in ($scope) and we can directly access data in controller also no need to create an object of the controller.
·       Controller has direct access to the scope. Scope merged with an object.












LEARN TUTORIALS

.

.