| author | rougeronj |
| Tue, 17 Mar 2015 16:34:23 +0100 | |
| changeset 14 | 4d27fbc3f9df |
| parent 8 | 824c87a9084c |
| child 54 | ccb586464a6f |
| permissions | -rw-r--r-- |
| 0 | 1 |
(function(){ |
|
14
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
2 |
'use strict'; |
| 0 | 3 |
|
4 |
||
|
14
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
5 |
angular.module('ammicoHome',['ngRoute']) |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
6 |
.config(function ($routeProvider) { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
7 |
$routeProvider |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
8 |
.when('/', { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
9 |
templateUrl: 'home/home.html', |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
10 |
controller: 'homeCtrl' |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
11 |
}); |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
12 |
}) |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
13 |
.service('booksModel', function(searchApi) { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
14 |
var _this = this; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
15 |
|
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
16 |
this.books = searchApi.getResource.query({action:'books', format:'json'}, function(data){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
17 |
_this.books = data; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
18 |
}); |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
19 |
}) |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
20 |
.controller('homeCtrl', function($scope, $location, booksModel){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
21 |
$scope.books = booksModel.books; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
22 |
$scope.searchSubmit = function(){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
23 |
$location.path('/search/' + $scope.q); |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
24 |
}; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
25 |
}) |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
26 |
.filter('meta', function() { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
27 |
return function(input, metaName) { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
28 |
var nb = input.length, i = 0, found = false; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
29 |
while(found===false && i<nb){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
30 |
if(input[i].name===metaName){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
31 |
found = true; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
32 |
return input[i].value; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
33 |
} |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
34 |
i++; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
35 |
} |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
36 |
return ''; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
37 |
}; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
38 |
}); |
| 0 | 39 |
|
40 |
})(); |