Angular.JS + CORS

Angular.JS with CORS/IE compatibility - using $http.defaults.useXDomain

by Ankit Patidar

HTML

<div ng-app="Test">
    <div ng-controller="corsCtrl">
      
    </div>
</div>

CSS

.active {
    color: red;
}

JavaScript

angular.module('Test',['ngResource'])
.controller('corsCtrl', function ($scope, $http, MyResource) {
    
   $http.defaults.headers.common['test1']= 'team';
   MyResource.get();
})

  
.factory('MyResource', function($resource, $http){
    
    
  $http({
    method: 'GET',
    url: 'url/to/xml'
  }).then(function successCallback(response) {
    $scope.apiResponse =  response;
    // this callback will be called asynchronously
    // when the response is available
  	}, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });
  
  return $resource('url/to/json');
})