Wednesday, July 27, 2016

AngularJS Interview Questions

What is AngularJS?
AngularJS is a JavaScript framework i.e. used to create single web page application. It follows MVC (Model View Controller) pattern. It is open source, cross browser compliant and easy to maintain.
AngularJS is a powerful JavaScript based development framework to create RICH Internet Application (RIA).
AngularJS provides developers options to write client side application (using JavaScript) in a clean MVC (Model View Controller) way.
Application written in AngularJS is cross-browser compliant. AngularJS automatically handles JavaScript code suitable for each browser.
AngularJS is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0.

What are the advantages of AngularJS?
allows us to create single page application
follows MVC pattern
predefined form validations
supports animation
open source
cross browser compliant
supports two way data binding
its code are unit testable

What are the disadvantages of AngularJS?
JavaScript Dependent: If end user disables JavaScript, AngularJS will not work.
Not Secured: It is JavaScript based framework so it is not safe to authenticate user through AngularJS only.

Is AngularJS dependent on JQuery?
No.

What is data binding in AngularJS?
Data binding is the automatic synchronization of data between model and view components. ng-model directive is used in data binding.


Data Binding is the automatic synchronization of data between model and view. There are two ways of data binding:
One way data binding (used in classical template)


Two way data binding (used in AngularJS template)

What IDE's are currently used for the development of AngularJS?
Eclipse
Visual Studio
WebStorm
TextMate etc.

What are the features of AngularJS?
MVC
Validations
Modules
Directives
Templates
Scope
Expressions
Data Binding
Filters
Services
Routing
Dependency Injection
Testing

What are controllers in AngularJS?
Controllers are JavaScript functions that are used to provide data and logic to HTML UI. It acts as an interface between Server and HTML UI.

What are the usage of controllers in AngularJS?
AngularJS Controllers are used to:
Set up initial state of the $scope object, and
Add behavior to the $scope object.

What are services in AngularJS?
Services are objects that can be used to store and share data across the application. AngularJS offers many built-in services such as $http i.e. used to make XMLHttpRequest.

What is scope in AngularJS?
Scope is an object that represents application model.
Each AngularJS application can have only one root scope but can have multiple child scopes.

What is template in AngularJS?
A template consists of HTML, CSS and AngularJS directives that are used to render dynamic view.

What is the use of filter in AngularJS?
A filter is used to format the value of expression to display the formatted output. AngularJS enables us to write our own filter.

Explain ng-app directive.
ng-app directive defines and links an AngularJS application to HTML. It also indicate the start of the application.

Explain ng-model directive.
ng-model directive binds the values of AngularJS application data to HTML input controls. It creates a model variable which can be used with the html page and within the container control( for example, div) having ng-app directive.

Explain ng-bind directive.
ng-bind directive binds the AngularJS Application data to HTML tags. ng-bind updates the model created by ng-model directive to be displayed in the html tag whenever user input something in the control or updates the html control's data when model data is updated by controller.

Explain ng-controller directive.
ng-controller directive tells AngularJS what controller to use with this view. AngularJS application mainly relies on controllers to control the flow of data in the application. A controller is a JavaScript object containing attributes/properties and functions. Each controller accepts $scope as a parameter which refers to the application/module that controller is to control.

Explain ng-init directive.
ng-init directive initializes an AngularJS Application data. It is used to put values to the variables to be used in the application.

Explain ng-repeat directive.
ng-repeat directive repeats html elements for each item in a collection.


Explain what is Angular Expression? Explain what is key difference between angular expressions and JavaScript expressions?
Like JavaScript,  Angular expressions are code snippets that are usually placed in binding such as {{ expression }}
The key difference between the JavaScript expressions and Angular expressions
  • Context : In Angular, the expressions are evaluated against a scope object, while the Javascript expressions are evaluated against the global window
  • Forgiving: In Angular expression evaluation is forgiving to null and undefined, while in Javascript undefined properties generates TypeError or ReferenceError
  • No Control Flow Statements: Loops, conditionals or exceptions cannot be used in an angular expression
  • Filters: To format data before displaying it you can use filters
Explain what are directives ? Mention some of the most commonly used directives in AngularJS application ? 
A directive is something that introduces new syntax, they are like markers on DOM element which attaches a special behavior to it. In any AngularJS application, directives are the most important components.
Some of the commonly used directives are ng-model, ng-App, ng-bind, ng-repeat , ng-show etc.

Explain what Angular JS routes does ?
Angular js routes enable you to create different URLs for different content in your application.  Different URLs for different content enables user to bookmark URLs to specific content.  Each such bookmarkable URL in AngularJS is called a route
A value in Angular JS is a simple object.  It can be a number, string or JavaScript object.  Values are typically used as configuration injected into factories, services or controllers. A value should be belong to an AngularJS module.
Injecting a value into an AngularJS controller function is done by adding a parameter with the same name as the value

What makes AngularJS better ?
  • Registering Callbacks: There is no need to register callbacks . This makes your code simple and easy to debug.
  • Control HTML DOM programmatically:  All the application that are created using Angular never have to manipulate the DOM although it can be done if it is required
  • Transfer data to and from the UI: AngularJS helps to eliminate almost all of the boiler plate like validating the form, displaying validation errors, returning to an internal model and so on which occurs due to flow of marshalling data
  • No initilization code: With AngularJS you can bootstrap your app easily using services, which auto-injected into your application in Guice like dependency injection style
Explain what is string interpolation in Angular.js ?
In Angular.js the compiler during the compilation process matches text and attributes using interpolate service to see if they contains embedded expressions.  As part of normal digest cycle these expressions are updated and registered as watches.

Mention the steps for the compilation process of HTML happens?
Compilation of HTML process occurs in following ways
  • Using the standard browser API, first the HTML is parsed into DOM
  • By using the call to the $compile () method, compilation of the DOM is performed.  The method traverses the DOM and matches the directives.
  • Link the template with scope by calling the linking function returned from the previous step
Explain what is directive and Mention what are the different types of Directive?
During compilation process when specific HTML constructs are encountered a behaviour or function is triggered, this function is referred as directive.  It is executed when the compiler encounters it in the DOM.
Different types of directives are
  • Element directives
  • Attribute directives
  • CSS class directives
  • Comment directives
Explain what is linking function and type of linking function?
Link combines the directives with a scope and produce a live view.  For registering DOM listeners as well as updating the DOM, link function is responsible. After the template is cloned it is executed.
  • Pre-linking function: Pre-linking function is executed before the child elements are linked.  It is not considered as the safe way for DOM transformation.
  • Post linking function: Post linking function is executed after the child elements are linked. It is safe to do DOM transformation by post-linking function
Explain what is injector?
An injector is a service locator.  It is used to retrieve object instances as defined by provider, instantiate types, invoke methods and load modules.  There is a single injector per Angular application, it helps to look up an object instance by its name.

Explain what is the difference between link and compile in Angular.js?
  • Compile function: It is used for template DOM Manipulation and collect all of the directives.
  • Link function: It is used for registering DOM listeners as well as instance DOM manipulation. It is executed once the template has been cloned.
Explain what is factory method in AngularJS?
For creating the directive, factory method is used.  It is invoked only once, when compiler matches the directive for the first time.  By using $injector.invoke the factory method is invoked.

Mention what are the styling form that ngModel adds to CSS classes ?
ngModel adds these CSS classes to allow styling of form as well as control
  • ng- valid
  • ng- invalid
  • ng-pristine
  • ng-dirty
Mention what are the characteristics of “Scope”?
  • To observer model mutations scopes provide APIs ($watch)
  • To propagate any model changes through the system into the view from outside of the Angular realm
  • A scope inherits properties from its parent scope,  while providing access to shared model properties, scopes can be nested to isolate application components
  • Scope provides context against which expressions are evaluated
Explain what is DI (Dependency Injection ) and how an object or function can get a hold of its dependencies ?
DI or Dependency Injection is a software design pattern that deals with how code gets hold of its dependencies.  In order to retrieve elements of the application which is required to be configured when module gets loaded , the operation “config” uses dependency injection.
These are the ways that object uses to hold of its dependencies
  • Typically using the new operator, dependency can be created
  • By referring to a global variable, dependency can be looked up
  • Dependency can be passed into where it is required
Explain the concept of scope hierarchy?  How many scope can an application have?
Each angular application consist of one root scope but may have several child scopes. As child controllers and some directives create new child scopes, application can have multiple scopes. When new scopes are formed or created they are added as a children of their parent scope. Similar to DOM, they also creates a hierarchical structure.

Explain what is the difference between AngularJS and backbone.js?
AngularJS combines the functionalities of most of the 3rd party libraries, it supports individual functionalities required to develop HTML5 Apps.  While Backbone.js do their jobs individually.

Who created Angular JS ?
Intially it was developed by Misko Hevery and Adam Abrons. Currently it is being developed by Google.






1 comment:

  1. Hi There,


    Gasping at your brilliance! Thanks a tonne for sharing all that content. Can’t stop reading. Honestly!

    I am new to Angular 2. I have an issue which I can’t find the solution.
    I am trying to develop a system which parses a file and send line by line (after parsing as json) to server.
    I have a loop which
    runs on the file and place a http.post request per line.
    In case of success, a second http.post to a different api is done.
    In case of failure of the first call, i want to print the error and the line in the file caused the error.
    The problem is that since this is a asynch call, i can’t make the second http.post because the response return only after all calls are done. When trying to get the row of the error, I get the last row in the file. snip code:
    for (var row = 0; row < rows.length; row++) {
    let strBody = JSON.stringify(row);
    res = this.http.post(url1, strBody, options)
    if(success) {
    strBody = JSON.stringify(res);
    this.http.post(url2, strBody, options)
    if(fail) {
    //add error to table in html including row and strBody + reason
    //the problem is when reaching this location row = rows.length
    }
    } else {
    //add error to table in html including row and strBody + reason
    //the problem is when reaching this location row = rows.length
    }
    }

    Super likes !!! for this amazing post. I think everyone should bookmark this.


    Thank you,
    Morgan

    ReplyDelete