Scope is a special javascript object which plays the role of joining controller with the views. Scope contains the model data. In controllers, model data is accessed via $scope object.
<script>
Following are the important points to be considered in above example.var mainApp = angular.module("mainApp", []); mainApp.controller("shapeController", function($scope) { $scope.message = "In shape controller"; $scope.type = "Shape"; }); </script> $scope is passed as first argument to controller during its constructor definition. $scope.message and $scope.type are the models which are to be used in the HTML page. We've set values to models which will be reflected in the application module whose controller is shapeController. We can define functions as well in $scope. Scope Inheritance Scope are controllers specific. If we defines nested controllers then child controller will inherit the scope of its parent controller.
<script>
Following are the important points to be considered in above example.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"; }); </script> We've set values to models in shapeController. We've overridden message in child controller circleController. When "message" is used within module of controller circleController, the overridden message will be used. |