-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
51 lines (41 loc) · 1.84 KB
/
controllers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// CONTROLLERS
/**
* Homepage controller
* @param homeController controller object name
* @param $scope {service} local scope model for homecontroller
* @param cityService {service} our named service that gives access to city data
*/
weatherApp.controller('homeController', ['$scope', '$location', 'cityService', function($scope, $location, cityService){
$scope.city = cityService.city;
$scope.$watch('city', function(){
cityService.city = $scope.city;
});
$scope.submit = function () {
$location.path('forecast');
}
}]);
/**
* Forecast page controller
* @param forecastController controller object for forecast page
* @param $scope {service} local scope model for forecastController
* @param $resource {service} for calling api and fetching data
* @param $log {service} logging service
* @param $filter {service} filter service for manipulating various data types (here for date type manipulation)
* @param $routeParams {service} used to collect url params
* @param cityService {service} our named service that gives access to city data
*/
weatherApp.controller('forecastController', ['$scope', '$log', '$filter', '$routeParams', 'cityService', 'weatherService', function($scope, $log, $filter, $routeParams, cityService, weatherService){
$scope.city = cityService.city;
$scope.days = $routeParams.days || '8';
$scope.weatherResult = weatherService.getWeather($scope.city, $scope.days);
// format date time
$scope.convertToDate = function(dt) {
// commented because we are passing the date format in template
// return $filter('date')( new Date(dt * 1000), 'hh a, MMM dd, yyyy');
return new Date(dt * 1000);
};
// format temperature. Not formatting because we are already receiving in °C
$scope.convertToCelcius = function(temp) {
return temp;
}
}]);