-
Notifications
You must be signed in to change notification settings - Fork 0
/
controllers.js
57 lines (51 loc) · 1.76 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
52
53
54
55
56
57
//controller.js
var app = angular.module('ajaxApp');
app.controller('FirstController' , ['$scope', '$http', function ($scope, $http){
$scope.name = 'ibo';
$scope.names = ['Max','Pelle','Calle'];
$scope.show = function () {
console.log('HEJ DÄR');
};
$scope.showData = function () {
var url = 'http://jsonplaceholder.typicode.com/posts';
$http.get(url)
.then(function (data){
$scope.data = data.data;
console.log(data.data)
});
};
$scope.visaBilder = function () {
var url = 'http://jsonplaceholder.typicode.com/photos';
$http.get(url)
.then(function (bilder){
// eftersom vad vi får tillbaka är i data array måste vi skriva så här
$scope.bilder = bilder.data;
console.log($scope.bilder)
});
}
}]);
app.controller('ResultsController', ['$scope', function ($scope){
$scope.name = 'Batman';
$scope.results = [
{ name: 'Peter', score: 4 },
{ name: 'Fredrik', score: 14 },
{ name: 'Moses', score: 44 },
];
}]);
app.controller('WeatherController', ['$scope', '$location', function($scope, $location){
$scope.weather = function (city){
$location.path('/weatherResults/' + city);
console.log(city);
};
}]);
app.controller('WeatherResultsController', ['$scope','$routeParams','getWeather', function($scope, $routeParams,getWeather){
var city = $routeParams.city;
getWeather.inputWeather(city)
.then(function (data){
console.log(data);
$scope.location = data.location.name;
$scope.temp_c = data.current.temp_c;
$scope.description = data.current.condition.text;
$scope.image = data.current.condition.icon;
});
}]);