Last active
August 29, 2015 13:56
-
-
Save telagraphic/9105662 to your computer and use it in GitHub Desktop.
XMLHttpRequest cannot load http://api.wunderground.com/api/9534fdd6bc6642cd/forecast/q/OH/Columbus.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.
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
'use strict'; | |
angular.module('weatherBetterApp', [ | |
'ngCookies', | |
'ngResource', | |
'ngSanitize', | |
'ngRoute' | |
]) | |
.config(function ($routeProvider) { | |
$routeProvider | |
.when('/', { | |
templateUrl: 'views/main.html', | |
controller: 'MainCtrl' | |
}) | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
}) | |
.config(['$httpProvider', function($httpProvider) { | |
$httpProvider.defaults.useXDomain = true; | |
delete $httpProvider.defaults.headers.common['X-Requested-With']; | |
} | |
]); |
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
'use strict'; | |
angular.module('weatherBetterApp') | |
.controller('MainCtrl', function ($scope, Weatherfeed) { | |
$scope.awesomeThings = [ | |
'HTML5 Boilerplate', | |
'AngularJS', | |
'Karma' | |
]; | |
$scope.weather.forecast = Weatherfeed.jsonRequest(); | |
}); |
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
<div class="header"> | |
<ul class="nav nav-pills pull-right"> | |
<li class="active"><a ng-href="#">Home</a></li> | |
<li><a ng-href="#">About</a></li> | |
<li><a ng-href="#">Contact</a></li> | |
</ul> | |
<h3 class="text-muted">Weather Better</h3> | |
</div> | |
<div class="row marketing"> | |
{{weather.forecast | json}} | |
</div> | |
<div class="footer"> | |
</div> |
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
'use strict'; | |
angular.module('weatherBetterApp') | |
.service('Weatherfeed', function Weatherfeed($q, $http) { | |
var apiKey = "9534fdd6bc6642cd"; | |
var type = "forecast"; | |
var state = "OH"; | |
var city = "Columbus"; | |
var apiUrl = "http://api.wunderground.com/api/9534fdd6bc6642cd/forecast/q/OH/Columbus.json"; | |
var getURL = function() { | |
return "http://api.wunderground.com/api/" + | |
apiKey + "/" + type + "/q/" + | |
state + "/" + city + '.json'; | |
}; | |
var getWeather = { | |
threeDayForecast: function() { | |
var p = $q.defer(); | |
$http({ | |
method: "GET", | |
url: getURL(), | |
cache: true | |
}).success(function(data) { | |
p.resolve(data.forecast.simpleForecast); | |
}).error(function(error) { | |
p.reject(error); | |
}); | |
return p.promise; | |
}, | |
jsonRequest: function() { | |
var p = $q.defer(); | |
$http.jsonp("http://api.wunderground.com/api/9534fdd6bc6642cd/forecast/q/OH/Columbus.json?callback=JSON_CALLBACK") | |
.success(function(data) { | |
p.resolve(data); | |
}) | |
.error(function(error) { | |
p.reject(error); | |
}); | |
return p.promise; | |
} | |
}; | |
return getWeather; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment