Scope inside controller:
<!DOCTYPE html>
<html lang="en-US">
<script src="angular.min.js"></script>
<script>
var mymodule=angular.module("mymodule",[]);
mymodule.controller("mycont",function($scope){
$scope.name="HeeraBabu";
});
</script>
<body>
<div ng-app="mymodule" ng-controller="mycont">
<h1>Hello {{name}}</h1>
</div>
</body>
</html>
- Here function($scope) ($scope) is a parameter through this parameter we will directly access our data(i.e. name) inside the controller.
- ($scope) can be defined with different syntax.
- ($scope) bind the data between HTML and JavaScript.
- It is used for the view and controller.
- A scope is an instance of JavaScript.
- There is another scope called $rootScope this is available in whole application both can contain different name of data but an application will definitely use the current scope.
- Scope joins the controller with the view.
- We pass the scope as a parameter in the function which can directly accessible in the controller.