|
Answer» The following diagram illustrates the scope lifecycle in AngularJS: - Creation: In this phase, the rootScope is created by $injector during the application bootstrap. During the phase of template linking, new child scopes relevant to the directives are created.
- Watcher registration: Here, the directives register the watches on the scope object which will be used to propagate values of models to DOM.
- Model MUTATION: The model mutations need to be PRESENT within the scope.$apply() for them to be properly observed. These will be done implicitly by AngularJS when WORKING on synchronous or asynchronous work requests.
- Mutation observation: Once the $apply is complete, the digest CYCLE STARTS to observe for any model mutations on the scopes. Here, the $watches expressions are monitored for the model mutations and if any mutations are observed, then the $watch listener is called on the model.
- Scope destruction: As and when the child scopes are unnecessary, the creator of the scopes would have to destroy them by making use of scope.$destroy(). This ensures that the $digest cycle propagations are stopped and the memory once used by the child scopes is reclaimed.
|