1. Question:What is the difference between Factory, Service and Provider? 

    Answer
    Factory - A factory is a simple function which allows you to add some logic before creating the object. It returns the created object.
    
    When to use: It is just a collection of functions like a class. Hence, it can be instantiated in different controllers when you are using it with constructor function.
    
    Service - A service is a constructor function which creates the object using new keyword. You can add properties and functions to a service object by using this keyword. Unlike factory, it doesn’t return anything.
    
    When to use: It is a singleton object. Use it when you need to share a single object across the application.
    For example, authenticated user details.
    
    Provider - A provider is used to create a configurable service object. It returns value by using $get() function.
    
    When to use: When you need to provide module-wise configuration for your service object before making it available.






    1. Report
  2. Question:What is the difference between $http and $resource? 

    Answer
    $http service is a core Angular service which allows you to make AJAX requests by using GET, HEAD, POST, PUT, DELETE, JSONP and PATCH methods. It is very much like the $.ajax() method in jQuery. It can be used with RESTful and Non-RESTful server-side data sources.
    
    $http is good for quick retrieval of server-side data that doesn’t really need any specific structure or complex behaviors.
    
    $resource warps $http and allows you to interact with RESTful server-side data sources. It requires the ngResource module to be installed which exist in angular-resource.js
    
    $http is good for retrieval of RESTful server-side data sources that might need any specific structure or complex behaviors.






    1. Report
  3. Question:What methods $http service support? 

    Answer
    The $http service supports the following methods:
    1. $http.get()
    2. $http.head()
    3. $http.post()
    4. $http.put()
    5. $http.delete()
    6. $http.jsonp()
    7. $http.patch()






    1. Report
  4. Question:How to enable caching in $http service? 

    Answer
    You can enable caching in $http service by setting configuration property cache to true. When cache is enabled, $http service stores the response from the server in local cache. In this way, next time the response will be served from the cache without sending request to server.
    $http.get("http://server/myserviceapi",{ cache:true }).sucess(function(){ 
    
    //TO DO: 
    
    });






    1. Report
  5. Question:What methods $resource service object support? 

    Answer
    The $resource service object supports the following methods:
    1. get()
    2. query()
    3. save()
    4. remove()
    5. delete()






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