Created
November 16, 2015 07:53
-
-
Save claytantor/258d8a5dfeda5dc105c7 to your computer and use it in GitHub Desktop.
How to enable CORS for AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="dronzeApp"> | |
<head> | |
<title>Hello World, AngularJS - ViralPatel.net</title> | |
<script type="text/javascript" | |
src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> | |
<script type="text/javascript"> | |
var dronzeApp = angular.module('dronzeApp', []); | |
dronzeApp.config(function($httpProvider) { | |
//Enable cross domain calls | |
$httpProvider.defaults.useXDomain = true; | |
//Remove the header containing XMLHttpRequest used to identify ajax call | |
//that would prevent CORS from working | |
delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
}); | |
dronzeApp.controller('CompanyStatements', function ($scope, $http) { | |
$http.get('http://ec2-52-24-100-54.us-west-2.compute.amazonaws.com:8080/rest/api/statement/dates/AAN') | |
.success(function(data) { | |
$scope.statements = data; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div ng-controller="CompanyStatements"> | |
<div>Statement ticker: {{statements.ticker}}</div> | |
<ul> | |
<li ng-repeat="date in statements.statementDates"> | |
<span>{{date}}</span> | |
</li> | |
</ul> | |
<p>Total number of statements: {{statements.statementDates.length}}</p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment