AngularJS Developer Question:
Download Questions PDF

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.
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";
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.

Download AngularJS Developer Interview Questions And Answers PDF

Previous QuestionNext Question
Explain me how do you reset a “$timeout”, and disable a “$watch()”?Explain me what are the advantages of using Angular.js framework?