-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
87 lines (60 loc) · 2.03 KB
/
Copy pathapp.js
File metadata and controls
87 lines (60 loc) · 2.03 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Module
var weatherApp=angular.module('weatherApp',['ngRoute','ngResource']);
/*
//Routes
weatherApp.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl:'pages/home.htm',
controller:'homeController'
})
.when('/forecast',{
templateUrl:'pages/forecast.htm',
controller:'forecastController'
})
.when('/forecast/:days',{
templateUrl:'pages/forecast.htm',
controller:'forecastController'
})
});
//Service
weatherApp.service('cityService',function(){
this.city="New York, NY";
});
//Controllers
weatherApp.controller('homeController',['$scope', 'cityService',function($scope, cityService){
$scope.city=cityService.city;
$scope.$watch('city',function(){
cityService.city=$scope.city;
});
}]);
weatherApp.controller('forecastController',['$scope','$resource','$routeParams','cityService',function($scope,$resource,$routeParams,cityService){
$scope.city=cityService.city;
$scope.days=$routeParams.days || '2';
console.log($scope.days);
$scope.weatherAPI=$resource("http://api.openweathermap.org/data/2.5/forecast/daily?APPID=e84614b91a23f5b336f5c428748b56e0",{
callback:"JSON_CALLBACK"},{get:{method:"JSONP"}});
$scope.weatherResult=$scope.weatherAPI.get({q:$scope.city,cnt:$scope.days});
//console.log($scope.weatherResult);
$scope.convertToFahrenheit=function(degK){
return Math.round(degK-273.15);
};
$scope.convertToDate=function(dt){
return new Date(dt*1000);
};
}]);
//Directive
weatherApp.directive('weatherReport',function(){
return{
restrict:"E",
templateUrl:'directives/weatherReport.html',
replace:true,
scope:{
weatherDay:"=" ,
convertToStandard:"&",
convertToDate: "&",
dateFormat:"@"
}
}
});
*/