AngularJS Scope

Scope is a special JavaScript object that connects controller with views. Scope contains model data. In controllers, model data is accessed via $scope object.


The following important points are considered in above example − <html >
<head>
<title>AngularJS filters</title>
</head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<body>
<h2>Sample Application</h2>
<div ng-app = "mainApp" ng-controller = "shapeController">
<p>{{message}} {{type}} </p>
<div ng-controller = "circleController">
<p>{{message}} {{type}} </p>
</div>
<div ng-controller = "squareController">
<p>{{message}} {{type}} </p>
</div>
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller("shapeController", function($scope) {
$scope.message = "In shape controller";
$scope.type = "Shape";
});
mainApp.controller("circleController", function($scope) {
$scope.message = "In circle controller";
});
mainApp.controller("squareController", function($scope) {
$scope.message = "In square controller";
$scope.type = "Square";
});
</script>
</body>
</html>