AngularJS Developer

  Home  Client Side Scripting  AngularJS Developer


“AngularJS Developer related Frequently Asked Questions by expert members with job experience as AngularJS Developer. These questions and answers will help you strengthen your technical skills, prepare for the new job interview and quickly revise your concepts”



125 AngularJS Developer Questions And Answers

22⟩ Please explain 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

 164 views

23⟩ Tell me 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.

 153 views

24⟩ Explain me what is AngularJS and what are some of its advantages?

This question might seem basic at first glance, but what you’re really doing is giving the developer a chance to show you what they know about your chosen framework. AngularJS is a powerful JavaScript-based development framework designed to create dynamic single-page applications with fewer lines of code. Some of the key advantages that you’ll want to look for in their response are listed below.

☛ Data binding is as easy as writing in your code.

☛ AngularJS was made for CRUD applications, which happen to represent the majority of web apps (excluding DOM manipulation-intensive applications like games and GUI editors).

☛ It separates DOM manipulation from app logic, making code modular and easy to test.

☛ It’s a comprehensive client-side solution in that it decouples the client-side from server-side development effort.

☛ It saves months of development time by freeing the developer from having to write repetitive low-level DOM manipulation tasks, manually registering callbacks, and otherwise automating most AJAX application tasks.

☛ It’s great for providing a “desktop-like” experience to the end user.

 158 views

25⟩ Tell me is it a good or bad practice to use AngularJS together with jQuery?

It is definitely a bad practice. We need to stay away from jQuery and try to realize the solution with an AngularJS approach. jQuery takes a traditional imperative approach to manipulating the DOM, and in an imperative approach, it is up to the programmer to express the individual steps leading up to the desired outcome.

AngularJS, however, takes a declarative approach to DOM manipulation. Here, instead of worrying about all of the step by step details regarding how to do the desired outcome, we are just declaring what we want and AngularJS worries about the rest, taking care of everything for us.

 172 views

26⟩ List down a few ways to improve performance in an AngularJS app?

The two officially recommended methods for production are disabling debug data and enabling strict DI mode.

The first one can be enabled through the $compileProvider:

myApp.config(function ($compileProvider) {

$compileProvider.debugInfoEnabled(false);

});

That tweak disables appending scope to elements, making scopes inaccessible from the console. The second one can be set as a directive:

<html ng-app=“myApp” ng-strict-di>

The performance gain lies in the fact that the injected modules are annotated explicitly, hence they don’t need to be discovered dynamically.

You don’t need to annotate yourself, just use some automated build tool and library for that.

Two other popular ways are:

Using one-time binding where possible. Those bindings are set, e.g. in “{{ ::someModel }}” interpolations by prefixing the model with two colons. In such a case, no watch is set and the model is ignored during digest.

Making $httpProvider use applyAsync:

myApp.config(function ($httpProvider) {

$httpProvider.useApplyAsync(true);

});

… which executes nearby digest calls just once, using a zero timeout.

 146 views

27⟩ Explain which means of communication between modules of your application are easily testable?

Using a service is definitely easy to test. Services are injected, and in a test either a real service can be used or it can be mocked.

Events can be tested. In unit testing controllers, they usually are instantiated. For testing events on $rootScope, it must be injected into the test.

Testing $rootScope against the existence of some arbitrary models is testable, but sharing data through $rootScope is not considered a good practice.

For testing direct communication between controllers, the expected results should probably be mocked. Otherwise, controllers would need to be manually instantiated to have the right context.

 168 views

28⟩ Tell me what is service method?

Using service method, we define a service and then assign method to it. We've also injected an already available service to it.

mainApp.service('CalcService', function(MathService){

this.square = function(a) {

return MathService.multiply(a,a);

}

});

 147 views

29⟩ Tell me filter filter?

filter filter is used to filter the array to a subset of it based on provided criteria.

In below example, to display only required subjects, we've used subjectName as filter.

Enter subject: <input type = "text" ng-model = "subjectName">

Subject:

<ul>

<li ng-repeat = "subject in student.subjects | filter: subjectName">

{{ subject.name + ', marks:' + subject.marks }}

</li>

</ul>

 147 views

30⟩ How to setup development environment for Angular2? Please follow the step by step approach with code configuration/screenshots?

In this section, the development environment setup has been described. Angularjs 2.0 application can be developed using:

angular-cli: This is a command line tool for Angularjs 2.0 application development which support live coding and deployment instantly. This is much easier and much straight forward.

systemjs: This is the traditional way of developing angularjs application. This way has been described in details later in Part-2.

 134 views

31⟩ 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.

 159 views

33⟩ Tell me how to implement internationalization in AngularJS?

AngularJS supports inbuilt internationalization for three types of filters currency, date and numbers. We only need to incorporate corresponding js according to locale of the country. By default it handles the locale of the browser. For example, to use Danish locale, use following script

<script src = "https://code.angularjs.org/1.2.5/i18n/angular-locale_da-dk.js"></script>

 159 views

37⟩ What is 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.

 153 views

38⟩ Explain me how to make an ajax call using Angular JS?

AngularJS provides $https: control which works as a service to make ajax call to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $https: can be used to get the data from server in the following manner:

function studentController($scope,$https:) {

var url = "data.txt";

$https:.get(url).success( function(response) {

$scope.students = response;

});

}

 153 views

39⟩ Explain me 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.

 146 views

40⟩ Explain currency filter in AngularJS?

One of the filters in AngularJS is the Currency Filter. This “currency” filter includes the “$” Dollar Symbol as the default. So we can use the following code as the html template format of Currency Filter.

{{ currency_expression | currency : symbol : fractionSize}}

How to use Currency Filter in AngularJS

There are two ways by which we can use Currency Filter.

Default

If we did not provide any currency symbol then by default Dollar-Sign will be used; we can use it as follows:

<!-- by default -->

Default Currency {{amount | currency}}

User Defined

To use different type of currency symbols we have to define our own symbol by using the unicode or Hexa-Decimal code of that Currency.

E.g. - For Example If we want to define Indian Currency Symbol then we have to use (Unicode-value) or (Hexa-Decimal value)

Indian Currency {{amount | currency:"&# 8377"}}

 161 views