AngularJS Interview Questions

AngularJS Interview Questions Download AngularJS Interview Questions PDF

AngularJS Interview Questions

The $ method is used to send an http post request in AngularJS. The method has three parameters namely URL, data, config.

In Angular js $scope is used whenever we have to use dependency injection (D.I) whereas as the scope is used for directive linking.

To animate the application, you need to include the AngularJS Animate Library and then refer to the ngAnimate module into the application or add ngAnimate as a dependency in your application module.

The transclusion in Angular JS will allow you to move the original children of a directive to a specific location inside a new template.The ng directive marks the insertion point for the transcluded DOM of the very near parent directive that uses transclusion.
ng-transclude or ng-transclude-slot attribute directives are used for transclusion in Angular JS.

Compile function: To template DOM manipulation and to gather all the directives, the compile function is used.
Link function: To register DOM listeners as well as for the instance DOM manipulation, the Link function is used.

It is used to prevent the Angular HTML template from getting displayed briefly by the browser in its uncompiled form while the application is still loading. It is used to avoid the undesirable flicker effect caused by HTML template display.

Scopeless controllers have no $scope injected and the functions and properties are binded directly onto the controller. Scopeless controllers are used in the situation where the controller becomes complex by using the $scope to provide data.

Caching can be enabled by setting the config.cache value or the default cache value to TRUE or to a cache object that is created with $cacheFactory.
In case you want to cache all the responses, then you can set the default cache value to TRUE.
And, if you want to cache a specific response, then you can set the config.cache value to TRUE.

Define a directive, use that directive on the element we are targeting and have it $watch a trigger/property to know when to focus the element.

locale service provides with the localization rules for Angular JS components.

Angular uses these prefixes to prevent accidental code collision with users code.
$ prefix is used with public objects whereas $$ prefix is used with a private object.

$templateCache is a Cache object that is created by the $cache factory. The first time you use a template, it is loaded in the $templateCache for easy and quick retrieval.

We can share data by creating a service, Services are easiest, fastest and cleaner way to share data between controllers in AngularJs.
There are also other ways to share data between controllers, they are

  • Using Events
  • $parent, nextSibling, controllerAs
  • Using the $rootScope

Difference between AngularJS and Angular 2

AngularJSAngular 2
Angular js or Angular 1.x is based on MVC ArchitectureAngular 2 is based on service/ components
Javascript is used to write applications in Angular js.Typescript (a superset of javascript) is used to write an application in Angular2.
A controller is used to writing logic and interact with Model and view.In Angular 2 Controllers are totally eliminated and Components take its place.
Angular 1 is created for developing Single page web-applications.In Angular 2 can be used for developing native applications for a mobile platform like React Native as well as interactive
web applications.
Angularjs is easy to set up, you just need to include the angular.js library to start.Angular 2 is dependent on other modules/ package. It gives little brainstorm to install and run Angular 2.
In Angularjs ng-app directive is used bootstrap the is removed in Angular 2. You need to call Angular2 bootstrap method to bootstrap your application.