PCBWay

Q. 1: What is AngularJS?

AngularJS is a javascript framework used for creating single web page applications.  It allows you to use HTML as your template language and enables you to extend HTML’s syntax to express your application’s components clearly.

Q.2: Who created Angular JS?

Initially it was developed by Misko Hevery and Adam Abrons. Currently it is being developed by Google.

Q.3: In which language, AngularJS is written?

javaScript

Q.4: Why this project is called “AngularJS”?

Html has angle brackets i.e. <,> and ng sound like Angular. That’s why it is called AngularJS.

Q.5: Is AngularJS a framework, library or a plugin?

The suitable answer is that it’s a framework. As its lightweight so people also get confused between library and framework.AngularJS is open source client side MVC framework for creating dynamic web applications.

Q.6: Does Angular use the jQuery library?

YES, Angular can use jQuery if it’s present in your app when the application is being bootstrapped. If jQuery is not present in your script path, Angular falls back to its own implementation of the subset of jQuery that we call jQLite.

Q.7: Is it same as jQuery?

NO. jQuery is great library for manipulating the DOM, providing better user experience with animations and effects. You can create website using jQuery but not a web application. jQuery is just a library to play around with HTML, whereas AngularJS is a framework to build a dynamic web app as it supports two data binding, MVC, allow testability, templates and many more. It’s like AngularJS like a toolbox and jQuery is just a tool.

Q.8: What are the key features/concepts of Angular.js?

When you start learning AngularJS, you will come across following terms and these are the features/concept of AngularJS.

  • Scope
  • Directives
  • Expression
  • Filters
  • Data Bindings
  • Model
  • View
  • Controller
  • Modules
  • Services
  • Dependency Injection

Q.9: What is the basic need to start with AngularJS?

To start with AngularJS, one need to make reference of angular.js. The latest version of AngularJS can be downloaded from AngularJS.com. You can either download the required js file and then host them locally or you can also use google CDN for referencing it. Here is the link for google CDN url for referencing AngularJS.

Q.10: What is the bootstrapping in AngularJS?

Bootstrapping in AngularJS is nothing but just initializing, or starting, your Angular app. AngularJS supports automatic bootstrapping as well as manual way as well.

Q.11: Why AngularJS?

AngularJS lets you extend HTML vocabulary for your application. The resulting environment is extraordinarily expressive, readable, and quick to develop.

  • 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.

Q.12: How does the AngularJS framework initialize itself?

The AngularJS has a self-executing anonymous function present in angular.js code, which does the initialization of AngularJS. Here is how below it looks,

(function(window, document, undefined) {

<!–here goes entire AngularJS code including functions, services, providers etc related code goes here–>

if (window.angular.bootstrap) {

//AngularJS is already loaded, so we can return here…

console.log(‘WARNING: Tried to load angular more than once.’);

return;

}

//try to bind to jquery now so that one can write angular.element().read()

//but we will rebind on bootstrap again.

bindJQuery();

publishExternalAPI(angular);

jqLite(document).ready(function() {

angularInit(document, bootstrap);

});

})(window, document);

Above function first check if Angular has already been setup. If it has, we return here to prevent Angular from trying to initialize itself a second time. And then it binds jQuery (if present) and publish external API. And finally angularInit() method does the trick for initialization of AngularJS.

Q.13: Is AngularJS is compatible with all modern browsers?

YES. AngularJS team run extensive test suite against the following browsers: Safari, Chrome, Firefox, Opera 15, IE9 and mobile browsers (Android, Chrome Mobile, iOS Safari).

Q.14: What are templates in AngularJS?

In Angular, templates are written with HTML that contains Angular-specific elements and attributes. Angular combines the template with information from the model and controller to render the dynamic view that a user sees in the browser. In other words, if your HTML page is having some Angular specific elements/attributes it becomes a template in AngularJS.

Q.15: What are different type or classification of directives?

AngularJS directives can be classified in 4 different types.

  • Element directives

<ng-directive></ng-directive>

  • Attribute directives

<span ng-directive></span>

  • CSS class directives

<span class=”ng-directive: expression;”></span>

  • Comment directives

<!– directive: ng-directive expression –>

Q.16: Can we create our own directives?

YES. AngularJS allows us to create our own custom directive.

Q.17: Can AngularJS have multiple ng-app directives in a single page?

The answer is 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 you have placed another ng-app directive then it will not be processed by AngularJS. You need to manually bootstrap the second app, instead of using second ng-app directive.

Q.18: What are directives in AngularJS?

Directives are markers on a DOM element (such as an attribute, element name, comment or CSS class) that tell AngularJS to attach a specified behavior to that DOM element or even transform the DOM element and its children. When AngularJS finds the directive at the time of rendering then it attaches the requested behavior to the DOM element. Angular comes with a set of these directives built-in, like ngBind, ngModel, and ngClass.

Q.19: Mention some angularJS directives and their purpose?

The beauty of AngularJS directives is that they are self explainatory. By just looking at directive name, you will get the idea about purpose and use of directive. Below are some mostly used directives.

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.

Event Listeners

ng-click : Click event to bind on HTML elements.

ng-dbl-click

Mouse event listeners

ng-mousedown

ng-mouseup

ng-mouseenter

ng-mouseleave

ng-mousemove

ng-mouseover

Keyboard event listeners

ng-keydown

ng-keyup

ng-keypress

ng-change

Q.20: Can you bootstrap multiple angular applications on same element?

NO. If you try to do that then it will show an error “App Already Bootstrapped with this Element”. This usually happens when you accidentally use both ng-app and angular.bootstrap to bootstrap an application. You can also get this error if you accidentally load AngularJS itself more than once.

Q.21: Can AngularJS have multiple ng-app directives in a single page?

The answer is 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 you have placed another ng-app directive then it will not be processed by AngularJS. You need to manually bootstrap the second app, instead of using second ng-app directive.

Q.22: What is the name of directive is used to bootstrap an angular app?

ng-app directive is used to auto-bootstrap an AngularJS application. The ng-app directive defines the root element of the application and is typically present in the root element of the page – e.g. on the <body> or <html> tags.

Q.23: Can angular applications (ng-app) be nested within each other?

NO. AngularJS applications cannot be nested within each other.

Q.24: In how many different ways, you can define a directive and what is the best practice?

Angular generally prefers camelCase for directives. But since HTML is not case-sensitive so it refers to directive in DOM in lower case form, delimited by dash (eg. ng-app). But when Angular complies then it normalize the directives.

Below are examples of valid directive declaration.

  • ng-model
  • ngModel
  • ng:model
  • ng_model
  • data-ng-model
  • x-ng-model

The normalization process is as follows:

1. Strip x- and data- from the front of the element/attributes.

2. Convert the :, -, or _-delimited name to camelCase.

The best practice to use dash-delimited (ng-model) or directly camelCase form (ngModel). If you are using HTML validation tool, then it is advised to use data- prefixed version.

Q.25: What is MVC Architecture in AngularJS?

In AngularJS, scope objects are treated as Model. The View is display of model that is your data. And the model gets initialized within a JavaScript constructor function, called Controller in AngularJS. Let take a look at below code to understand it better.

<!DOCTYPE html>
<html>
<head>
<script data-require=”angular.js@*” data-semver=”1.3.6″ src=”https://code.angularjs.org/1.3.6/angular.js”></script>
<link rel=”stylesheet” href=”style.css” />

<script>

var myApp = angular.module(‘myApp’, []);
myApp.controller(‘MyController’, [‘$scope’, function($scope) {
$scope.website = ‘jquerybyexample.net’;
}
]);

</script>

</head>

<body ng-app=”myApp”>

<div ng-controller=”MyController”>
<h1>My website address is {{ website }}</h1>;
</div>

</body>
</html>

Here MyController is a Controller and $scope (Model) is populated within Controller. And later on in div element $scope object data is displayed (View).

Q.26: How Angular expressions are different from JavaScript expressions?

Angular expressions are like JavaScript expressions but there are few differences.

Context : In Angular, the expressions are evaluated against a scope object, while the JavaScript expressions are evaluated against the global window object.

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.

No Comma And Void Operators: You cannot use , (comma) or void in an Angular expression. And You cannot create regular expressions in an Angular expression.

Q.27: What is scope in AngularJS?

A scope is an object that ties a view (a DOM element) to the controller. In the MVC framework, scope object is your model. In other words, it is just a JavaScript object, which is used for communication between controller and view.

Q.28: What are controllers in AngularJS?

In Angular, a Controller is a JavaScript constructor function. When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object, using the specified Controller’s constructor function. The job of a controller is to pass data from the model, to the view or the view can asks for something from the controller, and the controller turns to the model and takes that thing, and hands it back to the view.

var myApp = angular.module(‘myApp’, []);

myApp.controller(‘MyController’, [‘$scope’, function($scope) {

$scope.website = ‘jquerybyexample.net’;

}

]);

And then in your HTML using ng-controller directive,

<div ng-controller=”MyController”>

<h1>My website address is {{ website }}!</h1>

</div>

Q.29: What is Angular Expression?

Angular expressions are JavaScript-like code snippets that are usually placed in bindings such as {{ expression }}.

For example, these are valid expressions in Angular:

{{ 3+4 }}

{{ a+b }}

{{ user.name }}

{{ items[index] }}

Q.30: What is the difference between $scope and scope in AngularJS?

$scope is used while defining a controller (see previous question) where scope is used while creating a link function for custom directive. The common part is that they both refers to scope object in AngularJS, but the difference is that $scope uses dependency injection where scope doesn’t. When the arguments are passed-in via dependency injection, their position doesn’t matter. So for example, a controller defined as ($scope as first parameter)

myApp.controller(‘MyController’, [‘$scope’, function($scope, $http) {

OR ($scope is second parameter)

myApp.controller(‘MyController’, [‘$scope’, function($http, $scope) {

In both the case, the postion of $scope doesn’t matter to AngularJS. Because AngularJS uses the argument name to get something out of the dependency-injection container and later use it.

But in case of link function, the position of scope does matter because it doesn’t uses DI. The very first parameter has to be scope and that’s what AngularJS expects.

app.directive(“myDirective”, function() {

return {

scope: {};

link: function(scope, element, attrs) {

// code goes here.

}

};

});

However you can name it anything of your choice. In below code, foo is your scope object.

link: function(foo, bar, baz) {

// code goes here.

}

Q.31: What is $rootscope in AngularJS?

The $rootScope is the top-most scope. An app can have only one $rootScope which will be shared among all the components of an app. Hence it acts like a global variable. All other $scopes are children of the $rootScope. Since $rootScope is a global, which means that anything you add here, automatically becomes available in $scope in all controller. To add something in $rootScope, you need to use app.run function which ensures that it will run prior to the rest of the app. You may say that “run” function is like “main” method of angular app.

app.run(function($rootScope) {

$rootScope.name = “AngularJS”;

});

And then you can use in your view. (via expression)

<body ng-app=”myApp”>

<h1>Hello {{ name }}!</h1>

</body>

Q.32: What is compilation process in Angular?

Once you have the markup, the AngularJS needs to attach the functionality. This process is called “compilation” in Angular. Compiling includes rendering of markup, replacing directives, attaching events to directives and creating a scope. The AngularJS has compiler service which traverses the DOM looking for attributes. The compilation process happens in two phases.

Compilation: traverse the DOM and collect all of the directives and creation of the linking function.

Linking: combine the directives with a scope and produce a live view. The linking function allows for the attaching of events and handling of scope. Any changes in the scope model are reflected in the view, and any user interactions with the view are reflected in the scope model.

When you create a new directive, you can write compile and/or linking functions for it to attach your custom behavior.

Q.33: Can we have nested controllers in AngularJS?

YES. We can create nested controllers in AngularJS. Nested controller are defined in hierarchical manner while using in View. Take a look at below code. Here the hierarchy is “MainCtrl -> SubCtrl -> SubCtrl1″.

<div ng-controller=”MainCtrl”>

<p>{{message}} {{name}}!</p>

<div ng-controller=”SubCtrl”>

<p>Hello {{name}}!</p>

<div ng-controller=”SubCtrl2″>

<p>{{message}} {{name}}! Your username is  {{username}}.</p>

</div>

</div>

</div>

Q.34: In case of nested controllers, does the $scope object shared across all controllers?

YES. The $scope object is shared across all controllers and it happens due to scope inheritance. Since the ng-controller directive creates a new child scope, we get a hierarchy of scopes that inherit from each other. So if we define a property on a parent scope, the child scope can manipulate the property. And if the property is not present in child scope, then parent scope property’s value is used. Let’s consider, the previous question HTML where there are 3 controllers.And here is the AngularJS code to define these controllers.

var myApp = angular.module(‘myApp’, []);

myApp.controller(‘MainCtrl’, [‘$scope’, function($scope) {

$scope.message = ‘Welcome’;

$scope.name = ‘Jon’;

}

]);

myApp.controller(‘SubCtrl’, [‘$scope’, function($scope) {

$scope.name = ‘Adams’;

}

]);

myApp.controller(‘SubCtrl2’, [‘$scope’, function($scope) {

$scope.name = ‘Ema’;

$scope.username = ’ema123′;

}

]);

You will see that the controller “SubCtrl2” doesn’t have “message” property define but it is used in HTML. So in this case, the immediate parent scope property will be used. But immediate parent scope which is “SubCtrl” in this case, also doesn’t have “message” property. So it again goes one level up and finds the property is present so it uses parent scope value for “message” property and displays it.

Q.35: 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.

Q.36: 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.

Q.37: 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.

Q.38: 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.

Q.39: 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

Q.40: 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.

Q.41: Mention what are the advantages of using Angular.js framework ?

Advantages of using Angular.js as framework are

  • 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

Q.42: 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

Q.43: 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

Q.44: 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.

Q.45: With options on page load how you can initialize a select box?

You can initialize a select box with options on page load by using ng-init directive

  • <div ng-controller = “ apps/dashboard/account ” ng-switch
  • On = “! ! accounts” ng-init = “ loadData ( ) ”>

Q.46: 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.

Q.47: 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 initialization code: With AngularJS you can bootstrap your app easily using services, which auto-injected into your application in Guice like dependency injection style

Q.48: What is Data binding in AngularJS and how it works?

Data binding in generic term is “a process that establishes a connection between the application UI and business logic.” Same is true in case of Angular. Data-binding in Angular apps is the automatic synchronization of data between the model and view components. There are two types of bindings.

One Way – One way data binding is when model values are assigned to the HTML elements using data binding syntax like expression or ng-bind directive. But the change in HTML elements don’t change the values in the model. So its one-way.

Two Way – In simple terms two-way data binding is when the model changes, the view reflects the change, and vice versa. Two-way bindings in AngularJS are created with the ng-model directive. Practically, two-way bindings can be applied only to those elements that allow the user to provide a data value, which means the input, textarea, and select elements.

Q.49: What is ng-bind directive and how to use it?

ng-bind directive is used for displaying any model property value. It is same as {{ expression }}. But it is advisable to use ng-bind over expression. The reason is, when AngularJS is not loaded (for any reason), then ng-bind directive will not be visible. But in case of expression, whatever you have put within double curly brackets will be displayed in plain text.

<div ng-controller=”MyController”>

<h1>My website address is <span ng-bind=”website”></span></h1>

</div>

Q.50: What is ng-repeat directive and how to use it?

ng-repeat directive is just like for-each loop in C#. It’s like you iterate through a parent collection and process every child element. ng-repeat directive does exactly the same. Consider, you have following data and you want to display this in bulleted list.

$scope.users = [

{name: ‘John’,age: 25},

{name: ‘Adams’, age: 29},

{name: ‘Chris’, age: 31},

{name: ‘Eric’, age: 19},

{name: ‘Jon’, age: 29},

{name: ‘Ronald’, age: 27},

{name: ‘Ben’, age: 37},

{name: ‘Joe’, age: 26},

{name: ‘Henry’, age: 22},

{name: ‘Linda’, age: 16},

];

And in your view,

<ul>

<li ng-repeat=”user in users”>

{{user.name}} – {{user.age}} years.

</li>

</ul>

Q.51: What is ng-model directive and how to use it?

ng-model directive is used to bind model’s property to any input control like textbox, dropdown etc. It binds the view into the model.

<div ng-controller=”MyController”>

Enter any text : <input type=”text” name=”search” ng-model=”search” />

<h2>You have searched for <span ng-bind=”search”></span> !</h2>

</div>

And your model has a property named “search”.

var myApp = angular.module(‘myApp’, []);

myApp.controller(‘MyController’, [‘$scope’, function($scope) {

$scope.search = ‘nothing’;

}

]);

Q.52: What is ngShow and ngHide directives and how to use it?

ng-show and ng-hide directive allow to show or hide elements based on expression value. This is quite useful as you don’t have to do showing or hiding yourselves with CSS or JavaScript.

<div ng-hide=”true”>I’m hidden.</div>

<div ng-show=”true”>I’m shown.</div>

Or you can pass model values in expression.

<div ng-show=”prop1″></div>

So when $scope.prop1 is truthy (element is visible).

var myApp = angular.module(‘myApp’, []);

myApp.controller(‘MyController’, [‘$scope’, function($scope) {

$scope.prop1 = true;

$scope.prop2 = false;

}

]);

You can also pass function() as expression which returns true or false.

<div ng-hide=”IsInputCorrect()”></div>

Q.53: What is ng-submit directive and how to use it?

ng-submit directive is used to submit the form. But it only works when your form doesn’t contain any action attribute. You can pass a function name to ng-submit and when form is submitted, the function will get called.

<form ng-submit=”submit()” ng-controller=”SubmitController”>

Q.54: What are filters and how to use it?

Filters in Angular allows to select a subset of items using expression. Filters can be added to expressions and directives using a pipe character. Suppose we want to sort the names (previous question demo) and display the result, then we can use “orderBy” filter.

<ul>

<li ng-repeat=”user in users | orderBy:’name’ “>

{{user.name}} – {{user.age}} years.

</li>

</ul>

Another filter is “limitTo”

<ul>

<li ng-repeat=”user in users | limitTo:5 “>

{{user.name}} – {{user.age}} years.

</li>

</ul>

And you can also use filters with expression. For example, if you want to display name in uppercase then

<ul>

<li ng-repeat=”user in users “>

{{user.name | uppercase}} – {{user.age}} years.

</li>

</ul>

Below are list of filters supported by Angular.

  • filter: Selects a subset of items from array and returns it as a new array.
  • currency: Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default symbol for current locale is used.
  • number: Formats a number as text.
  • date: Formats date to a string based on the requested format.
  • json: Allows you to convert a JavaScript object into JSON string.
  • lowercase: Converts string to lowercase.
  • uppercase: Converts string to uppercase.
  • limitTo: Creates a new array or string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string or number, as specified by the value and sign (positive or negative) of limit.
  • orderBy: Orders a specified array by the expression predicate. It is ordered alphabetically for strings and numerically for numbers.

Q.55: What is ng-click and ng-change directive and how to use it?

The best part about AngularJS directives are that they are self explanatory. Just looking at the name, one can imagine what should be use of the directive. ng-click directive allows you to specify custom behavior when an element is clicked. And ng-change directive is used to find out when any value gets changed for input, select control.

Q.56: What is Module in AngularJS and what is angular.module?

“Module” in AngularJS is like container which can be used to contain different part of your application like controller, services, directives etc. Creating modules not only helps separating the code into individual concerns but makes them reusable and also improves unit-testability. Module can work independently and they can be dependent on other modules.Using angular.module, we can create module in AngularJS.

angular.module(‘module-name’,[dependencies]);

Every module should have a unique name, which is specified in the first parameter. Second parameter is an array, which may contain names of other dependent modules or services. If the module is not dependent then array should be left blank.

// Creating module with no dependency

var myModule = angular.module(‘myModule’, []);

//OR Creating module with dependency on other modules

angular.module(‘myApp’, [‘dependency1’, ‘dependency2’]);

Q.57: Does AngularJS has dependency on jQuery?

AngularJS has no dependency on jQuery library. But it can be used with jQuery library.

Q.58: How to use jQuery with AngularJS?

By default AngularJS use jQLite which is the subset of jQuery. If you want to use jQuery then simply load the jQuery library before loading the AngularJ. By doing so, Angular will skip jQLite and will started to use jQuery library.

Q.59: How to access jQLite or jQuery with AngularJS?

jQuery lite or the full jQuery library if available, can be accessed via the AngularJS code by using the element() function in AngularJS. Basically, angular.element() is an alias for the jQuery function i.e. angular.element() === jQuery() === $()

Q.60: What are the disadvantages of AngularJS?

Following are the disadvantages of AngularJS.

  • Not Secure − Being JavaScript only framework, application written in AngularJS are not safe. Server side authentication and authorization is must to keep an application secure.
  • Not degradable − If your application user disables JavaScript then user will just see the basic page and nothing more.

Q.61: How to make an ajax call using Angular JS?

AngularJS provides $http 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, $http can be used to get the data from server in the following manner:

function studentController($scope,$http) {

var url = “data.txt”;

$http.get(url).success( function(response) {

$scope.students = response;

});

}

Q.62: What is constant?

constants are used to pass values at config phase considering the fact that value cannot be used to be passed during config phase.

mainApp.constant(“configParam”, “constant value”);

Q.63: Is AngularJS extensible?

Yes! In AngularJS we can create custom directive to extend AngularJS existing functionalities.

Custom directives are used in AngularJS to extend the functionality of HTML. Custom directives are defined using “directive” function. A custom directive simply replaces the element for which it is activated. AngularJS application during bootstrap finds the matching elements and do one time activity using its compile() method of the custom directive then process the element using link() method of the custom directive based on the scope of the directive.

Q.64: What is internationalization?

Internationalization is a way to show locale specific information on a website. For example, display content of a website in English language in United States and in Danish in France.

Q.65: 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>

Q.66: What is provider?

Provider is used by AngularJS internally to create services, factory etc. during config phase(phase during which AngularJS bootstraps itself). Below mention script can be used to create MathService that we’ve created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.

//define a module

var mainApp = angular.module(“mainApp”, []);

//create a service using provider which defines a method square to return square of a number.

mainApp.config(function($provide) {

$provide.provider(‘MathService’, function() {

this.$get = function() {

var factory = {};

factory.multiply = function(a, b) {

return a * b;

}

return factory;

};

});

});