AngularJS 1x Interview Questions and Answers (36) - Page 2

What is the size of angular.js file?

The size of the compressed and minified file is < 36KB.
How AngularJS handle the security?

AngularJS provide following built-in protection from basic security holes:
1. Prevent HTML injection attacks.
2. Prevent Cross-Site-Scripting (CSS) attacks.
3. Prevent XSRF protection for server side communication.
What is Angular Prefixes $ and $$?

To prevent accidental name collisions with your code, Angular prefixes names of public objects with $ and names of private objects with $$. So, do not use the $ or $$ prefix in your code.
Explain how Angular JS Boot process works?

When ever we load any Angular Js application in the browser the following sequence of steps that happen:

Step 1: Just like as any request the HTML document will be loaded will be loaded and evaluated in the browser.After that the Angular Js file which was attached in the application gets loaded.

Step 2: Once that JS is being called the Global object is created after that the java script which registers the controller functions are executed.

Step 3: After that Angular Js will look for Angular Js Apps and Views. Once that view is being traced out it connects that view into the corresponding controller function

Step 4: Now Angular Js will execute the controller functions. It will render the views with data from model which is populated by the controller.

Step 5: Now the page is ready for the access.

This is how the Angular Js will control the flow from initial step to the final stage of page load functionality.
How to loop elements in Angular Js

Below is the procedure to loop through data in Angular JS

<div data-ng-app="" data-ng-init="names=['DotnetFunda','TechFunda','SQLFunda','ITFunda']">

<b>Loop Example:</b>
<br />
<ul>
<li data-ng-repeat="x in names">
{{ x }}
</li>
</ul>
</div>

How to create an object in Angular JS

Below is the way to create an object in Angular JS

<div ng-app="" ng-init="DnfObj={Str1:'Dotnet',Str2:'Funda'}">

String Display: <b>{{ DnfObj.Str2 }}</b></div>


Output will be: String Display: Funda
What is Angular Js?

NOTE: This is objective type question, Please click question title for correct answer.
What is the meaning of Directive in Angular Js? List some of them.

As the name suggests Directives are the ones which shows the direction on how the DOM elements to behave.

Directives are the markers on the DOM element just like an attribute like element name or Css Class which tells the Angular Js HTML compiler to add a specified behavior to the respective DOM element via event listeners which are available.

Some of the Directives are:

ng-app : It Initializes application.
ng-model : It Binds the HTML controls to application data.
ng-Controller : It Attaches a controller class to view.
ng-repeat : It Binds repeated HTML data elements. This is more or less like a for Loop
ng-if : It Binds HTML elements with a condition.
ng-show : It used to show the HTML elements.
ng-hide : It used to hide the HTML elements.
ng-class : It used to assign CSS class.
ng-src : It used to pass the URL image.
What is $rootscope and how it is useful?

$rootScope is just like a global variable which has the top most scope associated. Any app can have only one specific $rootScope which can be shared among all the components for that app.

Rest all $scopes will act as a children to the $rootScope. Since it is global any changes made to this will reflect in $scope of all other controllers. To add any thing in $rootScope we have to invoke app.run function. So it will ensure to run before to all other functionalities of the app.

app.run(function($rootScope) {

$rootScope.name = "AngularDotNetFunda";
});


The same can be used to print in this way

<body ng-app="myApp">

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

Can we have nested Controllers in Angular Js?

Yes we can have nested controllers. The thing is it works in a hierarchical way while using a View.

Example:

GrandFather ---- Father ---- Son

<div ng-controller="GrandFather">

<p>{{message}} {{name}}!</p>
<div ng-controller="Father">
<p>Hello {{name}}!</p>
<div ng-controller="Son">
<p>{{message}} {{name}}! Your username is {{username}}.</p>
</div>
</div>
</div>

How can we restrict Directives to be invoked only by specific methods?

We can restrict the Directive by using a Property "restrict" with value "A" so it will be invoked only by attributes.

var app = angular.module("myApp", []);

app.directive("DNFTestDirective", function() {
return {
restrict : "A",
template : "<h1>DotnetFunda is the best for Online Dotnet Support</h1>"
};
});

Which of the below command will help to call AngularJS function using JavaScript?

NOTE: This is objective type question, Please click question title for correct answer.
What is factory method in AngularJS?

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of $http?

NOTE: This is objective type question, Please click question title for correct answer.
What is the purpose of angular.module in AngularJS?

NOTE: This is objective type question, Please click question title for correct answer.
Which is the right format for calling a ng-bind function?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories