Thursday, November 5, 2015

AngularJS - What is scope hierarchy in AngularJS?

Ref :-

http://www.tutorialspoint.com/angularjs/angularjs_interview_questions.htm


Scopes are controllers specific. If we define nested controllers then child controller will inherit the scope of its parent controller.
<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";   
      });
</script>
Following are the important points to be considered in above example.
  • 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

No comments:

Post a Comment