Angular JS Interview Question Set 10

Categories: Angular JS

What can you say about the digest phase in AngularJS?

The digest cycle or digest phase is the most important cycle required for the data binding process. It does the task of comparing the old version of a model with its new version. Whenever a change in the scope model is found during the comparison, the model watches are fired and another digest phase is initiated until the scope model is stable.


What are the different phases of the lifecycle of AngularJS Scope?

The following diagram illustrates the scope lifecycle in AngularJS:

  1. 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.
  2. Watcher registration: Here, the directives register the watches on the scope object which will be used to propagate values of models to DOM.
  3. 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.
  4. 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.



How will you improve performance of an AngularJS application?

AngularJS makers have recommended the below two approaches for performance optimization in the production environment. They are:


Enable strict DI mode: This can be achieved by making use of the directive ngStrictDi and can be implemented as:

<html ng-app=“myFirstApp” ng-strict-di>

Disable debug data: This can be achieved by using the debugInfoEnabled method of the $compileProvider service as shown below:

app.config(function ($compileProvider) {

     $compileProvider.debugInfoEnabled(false);

});



What is the difference between the scopes of a directive and the scopes of a controller?

Scopes of the controller and the directives are the instances of scope objects. The only difference lies in the naming convention for them. To understand the difference between scope and $scope, we need to understand directives with isolated scope using the following code:


app.directive('testAppDirective', function() {

 return {

   scope: {},

   link: function(myScopeVariable, elem,attr) {

     console.log(scope);

   }

 }

});



How can you maintain logs in AngularJS?

Logs in AngularJS can be maintained by using the $log built-in service. These are mainly used for troubleshooting and debugging in case of any unexpected scenarios. They are done by mainly using the below methods:

  1. log(): To log a message onto the console. Example usage: $log.log(‘Entered some function’)
  2. info(): To write any message which represents information. Example usage: $log.info(‘Data processed successfully’)
  3. warn(): To log warnings. Example usage: $log.warn(‘The value is empty.’)
  4. error(): To log errors. Example usage: $log.error(‘Oh no! Something went wrong.’)
  5. debug(): To log any debug messages useful for debugging. Example usage: $log.debug(‘Processed a variable A.’)



How do you achieve internationalization?

Internationalization is a way of showing locale-specific content on our applications. For example, the website in the United Kingdom needs to be displayed in English whereas the same website needs to be shown in Hindi for the users of India. By incorporating multiple languages support in our platform, we are ensuring that our website reaches a wider target audience.


What is the auto bootstrap process?

Auto Bootstrapping is the process of automatically initiating the DOMContentLoaded event in the browser. The AngularJS application after downloading the angular.js library into the browser does the task of finding the ng-app directive which gives the root of the application. Once the directive is found, the following steps take place:


  1. The angular root module associated with the ng-app directive is loaded.
  2. The application injector is created which in turn creates the $compile and the $rootScope objects.
  3. The DOM is compiled from the ng-app element automatically and the content is rendered on the browser. This process is called auto bootstrapping.


What are the lifecycle hooks available?

There are many lifecycle hooks available in AngularJS and they are:

ngOnInit(): This is a callback method that gets invoked as soon as the change detector detects any scope model changes for the first time and before any view has been checked. This is invoked once only when the directive is instantiated.

ngOnChanges(): This callback function is triggered whenever AngularJS detects changes in the scope model and we can define the actions that need to follow up with that change in the property. It is called before ngOnInit() while instantiating the directive and is called every time the scope model changes.

ngDoCheck(): This callback method does the task of change-detection and is invoked only after the default change-detector is run.

Top Blogs
Dependency Injection and AngularJS Routes Published at:- AngularJS Templates, Views, Models, Controllers Published at:- Integrating AngularJS with Other Frameworks Published at:- Testing AngularJS Applications in the IDE Published at:- End-to-End Testing with Protractor Published at:- AngularJS Views and Bootstrap Published at:- Adding a New Blog Controller Published at:- Adding a New Blog Template In Angular JS Published at:- Ways to Communicate with REST Services Published at:- Services and Business Logic and Handling User Authentication in Angular JS Published at:- Using Basic Authentication, Creating AngularJS Services, Holding User Credentials in Angular JS Published at:- AngularJS Security : why we are covering security in a book on AngularJS Published at:- MEAN Cloud and Mobile, Local Deployment and Installing Node.js, npm, and MongoDB in Angular Published at:- Angular Js MCQ Quiz (Multiple Choice Question and answers) for beginners Published at:- Angular 4 Questions - Angular 4 Quiz (MCQ) Published at:- AngularJS MCQ Quiz Questions with Answer Part 2 Published at:- AngularJS MCQ Quiz Questions with Answer Published at:- AngularJS MCQ Quiz Questions with Answer Published at:- Angular JS Interview Question Set 1 Published at:- Angular JS Interview Question Set 2 Published at:- Angular JS Interview Question Set 3 Published at:- Angular JS Interview Question Set 3 Published at:- Angular JS Interview Question Set 4 Published at:- Angular JS Interview Question Set 5 Published at:- Angular JS Interview Question Set 6 Published at:- Angular JS Interview Question Set 6 Published at:- Angular JS Interview Question Set 8 Published at:- Angular JS Interview Question Set 9 Published at:- Angular JS Interview Question Set 10 Published at:- Angular JS Interview Question Set 11 Published at:- Angular JS Interview Question Set 12 Published at:- React versus Angular What Would it be advisable for You Pick Published at:- 9 Advantages of Angular you really want to be aware if you have any desire to assemble Computerized Items Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.