Angular JS Interview Questions
Most Frequently Asked Angular JS Interview Questions And Answers
- Scope: contains application data as well as methods
- Controller: controls the AngularJS applications
- Model: MVC based application widely used for modeling of data
- View: Content that is shown/ displayed as output to the user
- Services: A function or an object that is only available for AngularJS applications
- Data Binding: Process of synchronization of data automatically between model and view components.
- Directives: Markets on a DOM element that commands AngularJS to attach a particular behavior to a DOM element or to modify the same.
- Filters: Basically used in transforming data
- Testable: Ability to test the code
The scope can be defined as an application model that acts as a bridge between the view and application controller and binds both of them together. These are arranged in a hierarchical structure. The main function of scope is to impersonate the Document Object Model (DOM) structure of the application in use. Additional functionalities include keeping a watch on expressions and propagate several events inside the application. The scope comprises application data as well as methods. With the help of scope, the user can create properties, objects, etc inside a controller function and then he/she can assign a value to it.
|Expressions can be only evaluated against a global window||Expressions can be evaluated against a scope object|
|Here, properties which are not defined often generate errors such as TypeError or ReferenceError||Evaluation is forgiving to undefined as well as null|
A select box can be initialized with options on page load by using a particular directive called ng-init with the following lines of code :
<div ng-controller = " apps/dashboard/account " ng-switch On = "! ! accounts" ng-init = " loadData ( ) ">
With the help of directives, the developers can introduce new syntax. The directives can be defined as the markers on the DOM element which can attach a special behavior to it. In an AngularJS application, the most important components are the directives.
Some directives that are commonly used are
ng-model, ng-App, ng-bind, ng-repeat, ng-show, etc.
The advantages of using AngularJS as a framework are written below:
- It supports two-way data binding.
- MVC pattern is supported in AngularJS.
- The static and Angular template is supported in AngularJS.
- Custom directives can be added.
- Full REST services are supported in it.
- Form validations are also supported in it.
- Both server and client communication are supported in this framework.
- Dependency injection is supported in the AngularJS framework.
- Animations can be applied in the code.
- There are Event Handlers who are there in this framework.
AngularJS routes help the developer to develop various types of URLs specifically for a varied variety of content present in the application. Giving different URLs for different contents helps the user in bookmarking URLs easily to specific and only relevant content. Each URL that can be bookmarked in AngularJS can be defined as a route. Routes are the main reason why AngularJS is able to create single-page web applications so easily. It can also show more than one content depending upon the route chosen by the user. A route is easy to specify and can be done by specifying a '#' symbol after the URL which has been chosen for the same.
Services can be defined as those singleton objects.
Data Binding can be defined as automatic synchronization of data among the model and view components in AngularJS, which means it is passed from component to view and view to components. There are the following ways of data-binding:
- String Interpolation: It is one-way data binding. This text is between a set of curly braces that mostly uses the name of the component.
- Property Binding: This is the type that allows the developers to bind the view of the template expression.
- Event Binding: It is the updating or sending of value or the information of a specific variable from the view layer that is the presentation layer to the component that is a model layer.
- Two-way binding: It is a combination of Property and Event Binding.
AngularJS is better than other frameworks and to support this statement there are reasons that are defined below:
- Callback Registration: Generally there is no need for callback registration. With this the task of coding and debugging becomes easy.
- Controlling HTML DOM Programmatically: The applications that are created using Angular should never manipulate or alter the DOM, it can be done but only when required.
- Transferring Data to and from the UI: With AngularJS developers can eliminate mostly all the things like form validation, displaying errors and validation, returning to an internal model and so on. It occurs because of the flow of the data that is marshaling.
- No code initialization: With the help of AngularJS developers can easily bootstrap the programs or applications using its services. They are auto-injected into the applications in Guice like dependency injection style.
String interpolation is a special syntax in AngularJS with embedded expressions that provides data binding to text nodes as well as attribute values. In AngularJS, interpolation gives the facility of updating a string of text live on the basis of conditions of scope. Also, it allows the user to run the compilation of the template manually. During the development of the app with the help of AngularJS, the process of compilation matches the text as well as attributes using the interpolate service to check whether it contains embedded expressions. The expressions in AngularJS can always be updated and registered in the form of watches.