1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. Question:How to make an ajax call using Angular JS? 

    Answer
    AngularJS provides $http control which works as a service to make ajax call to read data from the server. The server makes a database call to get the desired records. AngularJS needs data in JSON format. Once the data is ready, $http can be used to get the data from server in the following manner:
    function studentController($scope,$http) {
       var url = "data.txt";
       $http.get(url).success( function(response) {
          $scope.students = response; 
       });
    }

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