1. 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
  2. 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
  3. 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
  4. 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
  5. 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 © 2025. Powered by Intellect Software Ltd