-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestAngular.html
75 lines (66 loc) · 2.09 KB
/
testAngular.html
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
<!DOCTYPE html>
<html class="no-js">
<head>
<!-- Meta-Information -->
<title>Media Center</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Vendor: Angular -->
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
</head>
<body ng-app="mediaCenter">
<div ng-controller="ctrl">
<div ng-repeat="torrent in torrents">
<p><b>Torrent --></b> {{torrent}}</p>
</div>
</div>
</body>
</html>
<script type="text/javascript">
/**
* Init angular module
*/
var app = angular.module('mediaCenter', []);
/**
* Controls torrents
*/
app.controller("ctrl", ['$scope', '$http', '$templateCache',
function ($scope, $http, $templateCache) {
// Get available torrents
$scope.getTorrents = function() {
// Http parameters
var config = {
/** Test purpose **/
url: 'http://jsonplaceholder.typicode.com',
/*url: 'http://api.t411.in/torrents/search/avatar',*/
method: 'GET',
/* headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Authorization',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'XXXXXXXXXXXXXXXXXXXX'
},*/
/*crossDomain: true,*/
/*cache: $templateCache*/
}
// Http call with params array
$http(config).
// Success request
then(function(response) {
console.log("success");
console.log(response);
$scope.torrents = response;
},function errorCallback(response) {
console.log("error");
console.log(response);
})
;
}
// Init torrents list
$scope.torrents = $scope.getTorrents();
/** Test purpose
$scope.torrents = [{'id': '1', 'body': 'content'},{'id': '2', 'body': 'content2'}];
**/
console.log($scope.torrents);
}]);
</script>