Menu ▼



Posted By :
avatarmrkraju
Total Views : 595

Angularjs interview questions:1

What is AngularJS?

AngularJS is a JavaScript framework to develop high performance web application by simplifying binding JavaScript objects with HTML elements. It provides option to develop client side development using JavaSript in MVC.

How to initialize AngularJS applicaiton data?

By using ng-init directive we can initialize the AngularJS app data.
Example

<div ng-app="myApp" ng-controller="myCntrl" ng-init="Qty=5;UnitPrice=6;">
</div>
Or
<div ng-app="myApp" ng-controller="myCntrl" ng-init="initval()">
</div>

<script language="javascript">
    var myapp = angular.module("myApp", []);
    myapp.controller("myCntrl", function ($scope) {
        $scope.initval = function(){
            $scope.Qty = 5;
            $scope.UnitPrice = 6;
        }
    });
</script>

See more about ng-init http://dotnetlearners.com/tutorial/angularjs/22/ng-init-directive-in-angularjs

What are the different custom directive types in AngularJS

There are 4 different types of custom directive in AngularJS

  • Element directives(E)
  • Attribute directives(A)
  • CSS class directives(C)
  • Common directives(M)
By using directive restrict property we can restrict the custom directive availability.
Example
myApp.directive("customdir", function(){
var dirout = {};
dirout.restrict = 'A';
//directive implementaiton
});
Usage
when directive restricted for Attribute level (A), then you can use the directive as
<div customdir></div>

But you cannot use it like an elements
<customdir></customdir>

What is the use of ng-repeat directive

We can use ng-repeat directive to repeat the html elements for each item in a collection. For example if you want to display the students list in a table or different coursed in a list element you can use ng-directive.Example

<table>
<thead>
<tr>
<th>Student Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="student in studentlist"">
<td>{{ student.Name}}</td>
</tr>
</tbody>
</table>
<ul>
<li ng-repeat="course in courselist">{{ course }}</li>
</ul>
See more about ng-repeat http://dotnetlearners.com/tutorial/angularjs/24/ng-repeat-directive-in-angularjs

Explain about expressions in AngularJS

  • AngularJS expressions are used to bind data to HTML like ng-bind directive
  • AngularJS expressions are similar to JavaScript expressions
  • Expressions are written inside double braces {{ expression }}
  • Expression can be written as one time binding
  • You can write expressions on
    • Numbers
    • Strings
    • Objects
    • Arrays
See more about AngularJS expression http://dotnetlearners.com/tutorial/angularjs/28/angularjs-expressions






comments powered by Disqus


Search dotnetlearners.com