AngularJS Interview Questions

AngularJS Interview Questions Download AngularJS Interview Questions PDF

AngularJS Interview Questions

Using ng-disabled attribute will help you disable element in AngularJS.

The AngularJS provides a date filter through which you can format the date into the required form.

Syntax

{{ today | date:'MM/dd/yyyy'}}

The template is the HTML portion of the angular app. It is exactly like a static HTML page, except that templates contain additional syntax which allows data to be injected in it in order to provide a customized user experience.

The $scope is an object with the available methods and properties. It is used to get all controls on the controller.JS files. It is available for both the controller and the view. "This" is the controller used when the controller’s constructor function is called.

The provider in AngularJS is used to internally create a factory, services etc., during the phase of configuration. The provider is the special factory method which is used to return the service/value/factory.

AngularJS is architecture on 3 components. They are

  • The Template (View)
  • The Scope (Model)
  • The Controller (Controller)

AngularJS extends HTML attributes with Directives and binds data to HTML with Expressions.

You can isolate a directive’s Scope by passing an object to the scope option of directive.
This tells the directive to keep scope inside of itself and not to inherit or share with other scopes.

The different types of directives available in AngularJS are:

  • Element directives − It activates when a matching element is encountered.
  • Attribute − It activates when a matching attribute is encountered.
  • CSS − It activates when a matching CSS style is encountered.
  • Comment − It activates when a matching comment is encountered.

It is a routing framework for AngularJS and provides a different approach than ngRoute. It changes the application views based on the state of the application and not just the route URL

To add promise functionality to a service, we inject the “$q” dependency in the service, and then use it like so:


angular.factory('testService', function($q){
return {
getName: function(){
var deferred = $q.defer();

//API call here that returns data
testAPI.getName().then(function(name){
deferred.resolve(name)
})

return deferred.promise;
}
}
})

The $q library is a helper provider that implements promises and deferred objects to enable asynchronous functionality

Source: https://docs.angularjs.org/api/ng/service/$q

In One-Way data binding, view (UI part) not updates automatically when data model changed. We need to write custom code to make it updated every time.
ng-bind has one-way data binding.

While in two way binding scope variable will change it’s value every time its data model changed is assigned to a different value.

AngularJS was designed to highlight the power of dependency injection, a software design pattern that places an emphasis on giving components of their dependencies instead of hardcoding them within the component. For example, if you had a controller that needed to access a list of customers, you would store the actual list of customers in a service that can be injected into the controller instead of hardcoding the list of customers into the code of the controller itself. In AngularJS you can inject values, factories, services, providers, and constants.

  • Create an angular.module
  • Assign a controller to the module
  • Link your module to HTML with ng-app
  • Link the controller to HTML with ng-controller directive

.config() – The .config() function is used to add configuration blocks on the module.

.run() - The .run() function is used to add run blocks on the module.

AngularJS is a framework with key features like models, two-way binding, directives, routing, dependency injections, unit tests etc., whereas the Jquery is a library used for DOM manipulation with no two-way binding features.