AngularJs Interview Questions and Answers Part 1

1. What is the difference between ng-bind and ng-model in angularjs?
Ans. ng-bind binds the application data to html control
     ng-model binds the html control data to application data.

2. Which directive defines the start of Angularjs application?
Ans. The ng-app directive defines an AngularJS application.

3. What prefix is used for Angularjs attributes?
Ans. "ng" prefix. Example: ng-init,ng-model,ng-bind,..

4. Give any example for variable inititalization using Angularjs?
Ans. Generally, variable initialization is done using "ng-init" directive.
For example,

<div ng-app="" ng-init="Name='ABC'">

<p>Welcome <span ng-bind="Name"></span></p>

</div>


5. Print 2 table using Angularjs?
Ans. 
<div>2x1={{2*1}}</div>
<div>2x2={{2*2}}</div>
<div>2x3={{2*3}}</div>
<div>2x4={{2*4}}</div>
<div>2x5={{2*5}}</div>
<div>2x6={{2*6}}</div>
<div>2x7={{2*7}}</div>
<div>2x8={{2*8}}</div>
<div>2x9={{2*9}}</div>
<div>2x10={{2*10}}</div>

6. why expressions are used in Angularjs?
Ans. Generally, AngularJS binds data to HTML using Expressions.

7. How to dynamically change the color of an target "Div" element on input type value using Angularjs?
Ans. We can dynamically change the color of any element using angularjs, for example

<div ng-app="" ng-init="ColorName='Yellow'">

<input ng-model="ColorName" value="{{ColorName}}">

<div style="background-color:{{ColorName}}">I am Changed !!</div>

</div>

8. Give any example of define arrays and how to access them in Angularjs?
Ans. We can declare and initialize array elements in angularjs using "ng-init",

 <div ng-app="" ng-init="StudentMarksArray=[30,35,46,57,44,67]">

<p>The first element is <span ng-bind="StudentMarksArray[0]"></span></p>

</div>


 






Subscribe

Receive Quality Tutorials Straight in your Inbox by submitting your Email below:

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker