Answers

Question and Answer:

  Home  AngularJS Developer

⟩ Tell me the concept of scope. How does scope inheritance work in AngularJS?

Scope is an object that represents the data-model of an AngularJS application—it is the glue between the view and the application controller. Scope inheritance closely mimics the DOM structure of the application. With the exception of isolated scopes created using custom directives, scopes follow prototypal inheritance. The code block below demonstrates typical scope inheritance.

<script>

var myApp = angular.module("myApp", []);

myApp.controller("fruitController", function($scope) {

$scope.message = "This is a Fruit";

$scope.type = "Fruit";

});

myApp.controller("appleController", function($scope) {

$scope.message = "This is an Apple";

});

</script>

The important thing to note in the above example is that values have been set to models in fruitController, and the message in appleController has been overridden.

 167 views

More Questions for you: