AngularJs Interview Questions and Answers Part 4

1. What is the output of the following code

    a. <p>Product : {{2 * 2}} </p> = ?

    b. <p>Product : {{2 " " 2}} </p> = ?

Ans: a. 4  b. 2 2

2. How to initialize mulitple arrays using ng-init?

Ans. 

<div ng-app = "" ng-init = "student = {firstname:'john',lastname:'paul',rollno:200};marks = [12,25,65,43,67]">
         <p>Hello {{student.firstname + " " + student.lastname}}!</p>        
         <p>Roll No: {{student.rollno}}</p>
         <p>Marks: {{marks[3]}}</p>
</div>


3. How many types filers does internationalization is supported in angularjs?

Ans. AngularJS supports inbuilt internationalization for three types of filters like currency, date and numbers.

4. By default which locale is supported in Angularjs?

Ans. By default it handles the locale of the browser.

5. Give any example for browser locale using Angularjs?

Ans. 

AngularJs Code :


            var myApp = angular.module("myApp", []);         
            myApp.controller('MyController', function($scope) {
            $scope.price = 200;
            $scope.currentdate  = new Date();
            $scope.total = 256.45;
         });
    

Html Code :

      <div ng-app = "myApp" ng-controller = "MyController">
         {{price | currency }}  <br/><br/>
         {{currentdate | date }}  <br/><br/>
         {{total | number }}
      </div>
 

6. What is ng-view in Angularjs?
Ans. ng-view tag creates a place holder where a html or ng-template view can be placed based on the configuration.

Example:

<div ng-app = "mainApp">
   
   <div ng-view>
    <!-- Target Html Template here -->
    </div>

</div>  

7. What is ng-template in Angularjs?
Ans. ng-template directive is used to create an html view using script tag.
     It contains "id" attribute which is used by $routeProvider to map a view with a controller.

Example : 

<div ng-app = "mainApp">      
  <scrip t type = "text/ng-template" id = "addEmployee.htm">
      <h2> Add Employee </h2>
      {{message}}
   </scrip t> 

</div>

$routeProvider part:

var mainApp = angular.module("mainApp", ['ngRoute']);

mainApp.config(['$routeProvider', function($routeProvider) {
   $routeProvider.
   
   when('/addEmployee', {
      templateUrl: 'addEmployee.htm', controller: 'AddEmployeeController'
   }).
 otherwise({
      redirectTo: '/addEmployee'
   });
    
}]);

8. What is $routeProvider in Angularjs?
Ans. $routeProvider is the key service which set the configuration of urls, map them with the corresponding html page or ng-template, and attach a controller with the same.

Example:

var mainApp = angular.module("mainApp", ['ngRoute']);

mainApp.config(['$routeProvider', function($routeProvider) {
   $routeProvider.
   
   when('/addEmployee', {
      templateUrl: 'addEmployee.htm', controller: 'AddEmployeeController'
   }).
 otherwise({
      redirectTo: '/addEmployee'
   });
    
}]);
 



Subscribe

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

Delivered by FeedBurner

Protected by Copyscape Duplicate Content Checker