Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Angular%20JS%20Interview%20Questions%20and%20Answers

Question: Can you explain the concept of scope hierarchy? How many scopes can an application have?
Answer:
Each Angular application has exactly one root scope, but may have several child scopes. The application can have multiple scopes, because child controllers and some directives create new child scopes. When new scopes are created, they are added as children of their parent scope. This creates a hierarchical structure similar to the DOM where they're attached.

When Angular evaluates a bound variable like say {{firstName}}, it first looks at the scope associated with the given element for the firstName property. If no such property is found, it searches the parent scope and so on until the root scope is reached. In JavaScript this behaviour is known as prototypical inheritance, and child scopes prototypically inherit from their parents. The reverse is not true. i.e. the parent can't see it's children's bound properties.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook