1. 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
  2. Question:What is use of $routeProvider in AngularJS? 

    Answer
    $routeProvider is the key service which set the configuration of urls, maps them with the corresponding html page or ng-template, and attaches a controller with the same.

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