From 83f2b54b5c2d0bae136d05e3fd7a1dc47540331b Mon Sep 17 00:00:00 2001 From: Carlos Mantilla Date: Tue, 7 Jul 2015 02:29:16 +0300 Subject: [PATCH] fix(weather, angularWeather): get temperature from city name. --- src/angular-weather.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/angular-weather.js b/src/angular-weather.js index af72a16..4718246 100644 --- a/src/angular-weather.js +++ b/src/angular-weather.js @@ -7,7 +7,7 @@ angular.module('angular-weather', []) apikey: '' } }) - .directive('angularWeatherTemperature', function () { + .directive('angularWeather', function () { return { restrict: 'EA', template: '
{{ctrlWeather.data.temperature | number:0 }}°
', @@ -15,7 +15,7 @@ angular.module('angular-weather', []) var vm = this; // Request the weather data. - weather.get(this.account).then(function(response) { + weather.get(vm.city).then(function(response) { vm.data = response; vm.data.iconClass = weatherIcons[response.icon]; }); @@ -24,11 +24,11 @@ angular.module('angular-weather', []) bindToController: true, // Isolate scope. scope: { - account: '=' + city: '@' } }; }) - .service('weather', function ($q, $http, $timeout, $state, $rootScope, openweatherEndpoint, weatherIcons, Config) { + .service('weather', function ($q, $http, $timeout, $rootScope, openweatherEndpoint, weatherIcons, Config) { var self = this; // A private cache key. @@ -43,15 +43,13 @@ angular.module('angular-weather', []) /** * Return the promise with the category list, from cache or the server. * - * @param accountId - int - * The account ID. - * @param categoryId - int - * The category ID. + * @param city - string + * The city name. Ex: Houston * * @returns {Promise} */ - this.get = function(account) { - getWeather = $q.when(getWeather || angular.copy(cache.data) || getWeatherFromServer(account)); + this.get = function(city) { + getWeather = $q.when(getWeather || angular.copy(cache.data) || getWeatherFromServer(city)); // Clear the promise cached, after resolve or reject the promise. Permit access to the cache data, when // the promise excecution is done (finally). @@ -67,12 +65,11 @@ angular.module('angular-weather', []) * * @returns {$q.promise} */ - function getWeatherFromServer(account) { + function getWeatherFromServer(city) { var deferred = $q.defer(); var url = openweatherEndpoint; var params = { - lat: account.center.lat, - lon: account.center.lng, + q: city, units: 'metric', APPID: Config.openweather.apikey || '' }; @@ -118,8 +115,6 @@ angular.module('angular-weather', []) * * @param getWeather - {$q.promise) * Promise of list of Weather, comming from cache or the server. - * @param accountId - int - * The account ID. * */ function prepareWeather(weatherData) {