1. Question:What is Routing in AngularJS? 

    Answer
    AngularJS Routing helps you to divide your app into multiple views and bind different views to Controllers. The magic of Routing is taken care by an AngularJS service $routeProvider. $routeProvider service provides method when() and otherwise() to define the routes for your app. Routing has dependency on ngRoute module.

    1. Report
  2. Question:Define $http service in AngularJS. 

    Answer
    The $http service is a core Angular service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.

    1. Report
  3. Question:What is Scope? 

    Answer
    Scope is an object that refers to the application model. It is an execution context for expressions. Scopes are arranged in hierarchical structure which mimic the DOM structure of the application. Scopes can watch expressions and propagate events.

    1. Report
  4. Question:What are services in AngularJS? 

    Answer
    Angular services are substitutable objects that are wired together using dependency injection (DI). You can use services to organize and share code across your app.Angular services are:
    Lazily instantiated – Angular only instantiates a service when an application component depends on it.
    Singletons – Each component dependent on a service gets a reference to the single instance generated by the service factory.

    1. Report
  5. Question:What is provider? 

    Answer
    provider is used by AngularJS internally to create services, factory etc. during config phase(phase during which AngularJS bootstraps itself). Below mention script can be used to create MathService that we've created earlier. Provider is a special factory method with a method get() which is used to return the value/service/factory.
    //define a module
    var mainApp = angular.module("mainApp", []);
    ...
    //create a service using provider which defines a method square to return square of a number.
    mainApp.config(function($provide) {
       $provide.provider('MathService', function() {
    	
          this.$get = function() {
             var factory = {};  
             factory.multiply = function(a, b) {
                return a * b; 
             }
             return factory;
          };
    		
       });
    });

    1. Report
  6. Question:What is $rootScope? 

    Answer
    Scope is a special JavaScript object which plays the role of joining controller with the views. Scope contains the model data. In controllers, model data is accessed via $scope object. $rootScope is the parent of all of the scope variables.

    1. Report
  7. Question:What is service method? 

    Answer
    Using service method, we define a service and then assign method to it. We've also injected an already available service to it.
    mainApp.service('CalcService', function(MathService){
       this.square = function(a) { 
          return MathService.multiply(a,a); 
    	}
    });

    1. Report
  8. Question:What is a service? 

    Answer
    Services are JavaScript functions and are responsible to do specific tasks only. Each service is responsible for a specific task for example, $http is used to make ajax call to get the server data. $route is used to define the routing information and so on. Inbuilt services are always prefixed with $ symbol.

    1. Report
  9. Question:What is factory method? 

    Answer
    Using factory method, we first define a factory and then assign method to it.
    var mainApp = angular.module("mainApp", []);
    mainApp.factory('MathService', function() {     
       var factory = {};  
    		
       factory.multiply = function(a, b) {
          return a * b 
       }
       return factory;
    });

    1. Report
  10. Question:What are the differences between service and factory methods? 

    Answer
    factory method is used to define a factory which can later be used to create services as and when required whereas service method is used to create a service whose purpose is to do some defined task.

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd