Skip to content

Angular service to use weatherforecast api from http://openweathermap.org/api #2

Open
@shafaiatul

Description

@shafaiatul

// SERVICES
weatherApp.service('cityService', function() {

this.city = "New York, NY";

});

//taking the weather API info and make a service out of it and then I will have the flexibility to use the service somewhere else
weatherApp.service('weatherService', ['$resource', function ($resource) {

this.GetWeather = function (city, days) {
var apiKey = '75ab4a21554c3eea638f0493fc501db1';
var weatherAPI = 
    $resource("http://api.openweathermap.org/data/2.5/forecast/daily", { callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }});

return weatherAPI.get({ q: city, cnt: days, APPID: apiKey });
};

}]);

_Hope this helps_***

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions