AngularJs Interview Questions and Answers Part 5

1. Can $scope object is injecttable in service in angularjs?
Ans. No, scope object cannot be injectable in service. It throws unknown provider error.

2. How to generate sequence number in Anuglarjs?
Ans. {{$index}} is used to generate sequence.

Example : 
 $scope.states = [{ name: 'ak' }, { name: 'us' }, { name: 'uk' }];

 <tr ng-repeat="str in states"><td>{{$index}}</td><td>{{}}</td></tr>

3. How to enable or disable text box on checkbox click using Angularjs?
Ans. using ng-model and ng-disabled,
<p>Enable/Disable Search : <input type="checkbox" ng-model="IsSearchEnable"/></p>
<p>Search : <input type="text" name="search" ng-model="search" ng-disabled="IsSearchEnable" /></p>

4. Which directives are used to validate data in Angularjs?
$dirty - states that value has been changed.
$invalid - states that value entered is invalid.
$error - states the exact error.

5. How to include html pages in Angularjs?
Ans. ng-include is used to embed html pages.
Example :
<div ng-app = "" ng-controller = "MyController">
   <div ng-include = "'Page1.htm'"></div>
   <div ng-include = "'Page2.htm'"></div>


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

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker