Angular JS 1.5 Questions

1. Explain data binding in AngularJS.
 “Data-binding in Angular apps is the automatic synchronization of data between the model and view components. The way that Angular implements data-binding lets you treat the model as the single-source-of-truth in your application. The view is a projection of the model at all times. When the model changes, the view reflects the change, and vice versa.”
There are two ways of data binding:
1                 Data mining in classical template systems
2                Data binding in angular templates

2. Name the key features of AngularJS?
The key features of AngularJS are:
Scope: Scope detect the changes in the Model objects and creates an execution context for expressions. There is one root scope for the application with hierarchical children Scopes. It arranges the Model to the View and forward the events to the Controller.
Controller: Controller is in charge of the construction of the Model and connecting it to the View. The Scope is situated between the Controller and the View. Controllers should contain the logic needed for a View. The Controllers should be thin with rich services.
Model: A Model is simply a JavaScript object that allows nested models.
View: The View is based on DOM objects, not on strings. The View is well suited for UI design as it is HTML and is declarative. The view is flexible and allows multiple Views per Controller.
Services: Services are singletons that perform common tasks for web applications. Services can be used when a common functionality needs to be shared between Controllers. Services can be built through Service API, Factory API, or with $provide API.
Data Binding: Data Binding  is a two-way binding between the View and the Model. Automatic synchronizing between Views and data Models makes it easy and uncomplicated to use.
Directives: Directives can be used to transform the DOM or to create new behavior. A Directive lets you extend the HTML vocabulary in a declarative fashion. AngularJS enables you to build your own directives.
Filters: Filters perform data transformation and can be used to do formatting and filter searching.
Testable: Testing is a mission-critical factor for enterprise applications. There are several different ways to write and run tests against JavaScript code, a.k.a  AngularJS. Jasmine Tests and Testacular are some of the recommended methods of testing as they are uncomplicated and easy.
Validation:AngularJS has a couple of built-in validation around HTML5 input variables and Directives. Creating your own validation is as simple as creating a Directive to perform your validation.

3. What are directives in AngularJS?
A core feature of AngularJS, directives are attributes that allow you to invent new HTML syntax, specific to your application. They are essentially functions that execute when the Angular compiler finds them in the DOM.  Some of the most commonly used directives are ng-app,ng-controller and ng-repeat.
The different types of directives are:
·         Element directives
·         Attribute directives
·         CSS class directives
·         Comment directives
4. What are Controllers in AngularJS?
Controllers are Javascript functions which provide data and logic to HTML UI. As the name suggests, they control how data flows from the server to HTML UI.

5. What is Angular Expression? How do you differentiate between Angular expressions and JavaScript expressions?
Angular expressions are code snippets that are usually placed in binding such as {{ expression }} similar to JavaScript.
The main differences between Angular expressions and JavaScript expressions are:
Context : The expressions are evaluated against a scope object in Angular, while Javascript expressions are evaluated against the global window
Forgiving: In Angular expression, the evaluation is forgiving to null and undefined whereas in JavaScript undefined properties generate TypeError or ReferenceError
No Control Flow Statements: We cannot use loops, conditionals or exceptions in an Angular expression
Filters: In Angular unlike JavaScript, we can use filters to format data before displaying it
6. What is the difference between link and compile in Angular.js?
Compile function is used for template DOM Manipulation and to collect all the directives.
Link function is used for registering DOM listeners as well as instance DOM manipulation and is executed once the template has been cloned.
7. What are the characteristics of ‘Scope’?
Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events. The characteristics of Scope are:
Scopes provide APIs ($watch) to observe model mutations.
Scopes provide APIs ($apply) to propagate any model changes through the system into the view from outside of the “Angular realm” (controllers, services, Angular event handlers).
Scopes can be nested to limit access to the properties of application components while providing access to shared model properties. Nested scopes are either “child scopes” or “isolate scopes”. A “child scope” (prototypically) inherits properties from its parent scope. An “isolate scope” does not. See isolated scopes for more information.
Scopes provide context against which expressions are evaluated. For example {{username}} expression is meaningless, unless it is evaluated against a specific scope which defines the username property.

8. What are the advantages of using Angular.js framework?
Angular.js framework has the following advantages:

·        Supports two way data-binding
·         Supports MVC pattern
·         Support static template and angular template
·         Can add custom directive
·         Supports REST full services
·         Supports form validations
·         Support both client and server communication
·         Support dependency injection
·         Applying Animations
·         Event Handlers

 9. What is the difference between AngularJS and backbone.js?
AngularJS combines the functionalities of most third party libraries and supports individual functionalities required to develop HTML5 Apps.  While Backbone.js does these jobs individually.
10. Explain what is injector in AngularJS?
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.

11. What is factory method in AngularJS?
Factory method is used for creating a directive.  It is invoked when the compiler matches the directive for the first time. We can invoke the factory method using $injector.invoke.
Syntax: module.factory('factoryName',function);
Result: When declaring factoryName as an injectable argument you will be provided with the value that is returned by invoking the function reference passed to module.factory.
12. What is ng-app, ng-init and ng-model?
  • ng-app : Initializes application.
  • ng-model : Binds HTML controls to application data.
  • ng-Controller : Attaches a controller class to view.
  • ng-repeat : Bind repeated data HTML elements. Its like a for loop.
  • ng-if : Bind HTML elements with condition.
  • ng-show : Used to show the HTML elements.
  • ng-hide : Used to hide the HTML elements.
  • ng-class : Used to assign CSS class.
  • ng-src : Used to pass the URL image etc.
13. Does Angular use the jQuery library?
Yes, Angular can use jQuery if it’s present in the app when the application is being bootstrapped. If jQuery is not present in the script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.
14. Can AngularJS have multiple ng-app directives in a single page?
No. Only one AngularJS application can be auto-bootstrapped per HTML document. The first ngApp found in the document will be used to define the root element to auto-bootstrap as an application. If another ng-app directive has been placed then it will not be processed by AngularJS and we will need to manually bootstrap the second app, instead of using second ng-app directive.
15. Can angular applications (ng-app) be nested within each other?
No. AngularJS applications cannot be nested within each other.
16. What is internationalization and how to implement it in AngularJS?
Internationalization is a way in which you can show locale specific information on a website. AngularJS supports inbuilt internationalization for three types of filters: currency, date and numbers. To implement internalization, we only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser.
17. On which types of component can we create a custom directive?
AngularJS provides support to create custom directives for the following:
    • Element directives − Directive activates when a matching element is encountered.
    • Attribute − Directive activates when a matching attribute is encountered.
    • CSS − Directive activates when a matching css style is encountered.
    • Comment − Directive activates when a matching comment is encountered.
18. What is $rootscope in AngularJS?
Every application has a single root scope. All other scopes are descendant scopes of the root scope. Scopes provide separation between the model and the view, via a mechanism for watching the model for changes. They also provide event emission/broadcast and subscription facility.
19. Can we have nested controllers in AngularJS?
Yes, we can create nested controllers in AngularJS. Nested controllers are defined in hierarchical manner while using in View.
20. What is bootstrapping in AngularJS?
Bootstrapping in AngularJS is nothing but initializing, or starting the Angular app. AngularJS supports automatic and manual bootstrapping.
  • Automatic Bootstrapping: this is done by adding ng-app directive to the root of the application, typically on the tag or tag if you want angular to bootstrap your application automatically. When angularJS finds ng-app directive, it loads the module associated with it and then compiles the DOM.
  • Manual Bootstrapping: Manual bootstrapping provides you more control on how and when to initialize your angular App. It is useful where you want to perform any other operation before Angular wakes up and compile the page.
21. What does SPA (Single Page Application) mean? How can we implement SPA with Angular?
Single Page Applications (SPAs) are web apps that load a single HTML page and dynamically update that page as the user interacts with the app. In an SPA the page never reloads, though parts of the page may refresh. This reduces the round trips to the server to a minimum.
It’s a concept where we create a single shell page or master page and load the webpages inside that master page instead of loading pages from the server by doing post backs. We can implement SPA with Angular using Angular routes. You can read up about SPAs here.
22. Why AngularJS?
AngularJS lets us extend HTML vocabulary for our application resulting in an expressive, readable, and quick to develop environment . Some of the advantages are:
  •     MVC implementation is done right.
  •     It extends HTML using directives, expression and data binding techniques to define a powerful HTML template.
  •     Two way data-binding, form validations, routing supports, inbuilt services.
  •     REST friendly.
  •     Dependency injection support.
  •     It helps you to structure and test your JavaScript code.
23. Is AngularJS compatible with all browsers?
Yes AngularJS is compatible with the following browsers: Safari, Chrome, Firefox, Opera 15, IE9 and mobile browsers (Android, Chrome Mobile, iOS Safari).
24. How to implement routing in AngularJS?
It is a five-step process:
  • Step 1: – Add the “Angular-route.js” file to your view.
  • Step 2: – Inject “ngroute” functionality while creating Angular app object.
  • Step 3: – Configure the route provider.
  • Step 4: – Define hyperlinks.
  • Step 5: – Define sections where to load the view.
25. Explain $q service, deferred and promises.
  • ‘Promises’ are post processing logics which are executed after some operation/action is completed whereas ‘deferred’ is used to control how and when those promise logics will execute.
  • We can think about promises as “WHAT” we want to fire after an operation is completed while deferred controls “WHEN” and “HOW” those promises will execute.
  • “$q” is the angular service which provides promises and deferred functionality.
These are some of the frequently asked AngularJS interview questions with answers. You can brush up on your knowledge of AngularJS with these blogs. You can also access a tutorial here.
Feeling overwhelmed with all the questions the interviewer might ask in your AngularJS interview? It’s never too late to strengthen your basics. Learn from industry experts on how to use AngularJS in real life use cases via a structured course.

26. Steps to create an AngularJS application:
The following are the steps to create an AngularJS applications:
Step 1 – Include AngularJS
Step 2 – Bootstrap the App
Step 3 – Create the Controller
Step 4 – Create the View
Step 5 – Run the Application

27. What is the difference between AngularJS and BackboneJS?
AngularJS combines the functionalities of third party libraries and individual functionalities required to develop HTML5 apps while BackboneJS does its jobs individually.

28)  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.

30)  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.
32)  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



Comments

  1. Hello Buddy,

    I love all the posts, I really enjoyed.
    I would like more information about this, because it is very nice., Thanks for sharing.

    We are trying to automate Angular JS App using a combination of chromedriver and Javascript. we had problems in identifying the tree view controls in the angular app

    code looks like this:
    var webdriver = require('selenium-webdriver');
    var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
    driver.get('URL');

    I have tried using CSS and Xpath but while executing it in the command line it prompts as Xpath as Undefined or CSS as undefined.

    Very useful post !everyone should learn and use it during their learning path.

    MuchasGracias,
    Irene Hynes

    ReplyDelete
  2. Thank you for sharing this useful blog. It will help to improve my career. Also, it is a wonderful blog for everyone.
    Angular 4 Training in Chennai | AngularJS Training Chennai | AngularJS Courses in Chennai | Angular Training in Chennai

    ReplyDelete

Post a Comment

Popular posts from this blog

Angular Question

AngularJS Tricky Questions