Angular JS Interview Question Set 9

Categories: Angular JS

What does the following code do? What are the permitted values of the restrict attribute?

app.directive('myFirstDirective', function() {

 return {

   restrict: 'E',

   scope: {

     directiveInfo: '=directiveInfo'

   },

   templateUrl: 'my-first-directive.html'

 };

});



 Differentiate between compile and link in AngularJS?

Compile is like a service used for traversing the HTML to find all the directives and return link functions.

The link does the task of combining the model with a view where any changes made to the model are reflected in the view and vice versa.



How does routing work in AngularJS?

Routing enables us to create different URLs according to different contents in our app which in turn enables the users of the application to bookmark the contents as per their requirements. The route is that URL that can be bookmarked. Routing also helps in developing SPA (Single Page Applications) i.e create a single HTML page and update that page dynamically as and when the user interacts.



Write a syntax to send sample HTTP POST request in AngualrJS?

To perform any AJAX calls, AngularJS makes use of the $http service. The syntax is as below:


$http({

      method: "POST",

      url: "URL",

      data: JSON.stringify(value),

      contentType: 'application/json'

  }).then(function (successResponse)

      {

          // success callback action of the request

      },function (errorResponse)

      {

          // error callback action of the request

      });



What is the importance of the $location service?

$location is one of the built-in AngularJS services that helps to keep track of the application’s URL, parses it, and makes the value available to the controller. In case the $location value is changed in the controller, the same is reflected on the browser’s address bar. Changes to the URL on the address bar also result in reflection of the same on the $location service.



What is the importance of orderBy?

orderBy is a built-in filter in AngularJS that helps to re-order the array items based on defined criteria. For example, if we need to sort the items based on the ascending order of price, then we can follow the below code:

<ul>

<li ng-repeat = "item in items | orderBy:'price">

     {{ item.name + ', price:' + item.price }}

</li>

</ul>



 Why do we use ng-include?

The ng-include directive is used for helping us to embed HTML pages inside a single HTML page. For example:

<div ng-app = "" ng-controller = "interviewBitController">

  <div ng-include = "'sample.htm'"></div>

  <div ng-include = "'example.htm'"></div>

</div>



Is it possible to create nested controllers?

Yes, it is possible to create nested controllers in AngularJS.

The sample code snippet can be as shown below:

<div ng-controller="mainController">

    <p>{{message}} {{name}}!</p>

   <div ng-controller="childController1">

       <p>Welcome to our app, {{name}}!</p>

      <div ng-controller="subChildController2">

            <p>{{message}} {{name}}! You are our esteemed guest {{name}}.</p>

      </div>

   </div>

</div>



What are AngularJS filters?

AngularJS filters are mainly used for formatting an expression while displaying it to the user. These can be used in controllers or services or views. AngularJS provides several inbuilt filters such as currency, filter, date, JSON, limitTo, etc whose purpose is to format the data without actually changing its value before merging to the expression and this is done by using the pipe character (|). AngularJS also provides support for registering and implementing custom filters and use them using the pipe symbol.



Top Blogs
Dependency Injection and AngularJS Routes Published at:- AngularJS Templates, Views, Models, Controllers Published at:- Integrating AngularJS with Other Frameworks Published at:- Testing AngularJS Applications in the IDE Published at:- End-to-End Testing with Protractor Published at:- AngularJS Views and Bootstrap Published at:- Adding a New Blog Controller Published at:- Adding a New Blog Template In Angular JS Published at:- Ways to Communicate with REST Services Published at:- Services and Business Logic and Handling User Authentication in Angular JS Published at:- Using Basic Authentication, Creating AngularJS Services, Holding User Credentials in Angular JS Published at:- AngularJS Security : why we are covering security in a book on AngularJS Published at:- MEAN Cloud and Mobile, Local Deployment and Installing Node.js, npm, and MongoDB in Angular Published at:- Angular Js MCQ Quiz (Multiple Choice Question and answers) for beginners Published at:- Angular 4 Questions - Angular 4 Quiz (MCQ) Published at:- AngularJS MCQ Quiz Questions with Answer Part 2 Published at:- AngularJS MCQ Quiz Questions with Answer Published at:- AngularJS MCQ Quiz Questions with Answer Published at:- Angular JS Interview Question Set 1 Published at:- Angular JS Interview Question Set 2 Published at:- Angular JS Interview Question Set 3 Published at:- Angular JS Interview Question Set 3 Published at:- Angular JS Interview Question Set 4 Published at:- Angular JS Interview Question Set 5 Published at:- Angular JS Interview Question Set 6 Published at:- Angular JS Interview Question Set 6 Published at:- Angular JS Interview Question Set 8 Published at:- Angular JS Interview Question Set 9 Published at:- Angular JS Interview Question Set 10 Published at:- Angular JS Interview Question Set 11 Published at:- Angular JS Interview Question Set 12 Published at:- React versus Angular What Would it be advisable for You Pick Published at:- 9 Advantages of Angular you really want to be aware if you have any desire to assemble Computerized Items Published at:- Top 20 Angular 10 Inquiries Questions and Answer Published at:- 9 Advantages of Angular you want to be aware to assemble Advanced Items Published at:- Top 5 Elements Angular Favored Decision for Web Improvement Published at:- Exploring the Latest Version of AngularJS: What's New and Exciting Published at:-
R4R.co.in Team
The content on R4R is created by expert teams.