| author | rougeronj |
| Thu, 02 Apr 2015 12:06:51 +0200 | |
| changeset 54 | ccb586464a6f |
| parent 14 | 4d27fbc3f9df |
| child 55 | 10fd23382e76 |
| 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 |
}) |
| 54 | 20 |
.controller('homeCtrl', function($scope, $location){ |
|
14
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
21 |
$scope.searchSubmit = function(){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
22 |
$location.path('/search/' + $scope.q); |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
23 |
}; |
|
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 |
.filter('meta', function() { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
26 |
return function(input, metaName) { |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
27 |
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
|
28 |
while(found===false && i<nb){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
29 |
if(input[i].name===metaName){ |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
30 |
found = true; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
31 |
return input[i].value; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
32 |
} |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
33 |
i++; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
34 |
} |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
35 |
return ''; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
36 |
}; |
|
4d27fbc3f9df
Succed to get the books from our api server and print them dynamically
rougeronj
parents:
8
diff
changeset
|
37 |
}); |
| 0 | 38 |
|
39 |
})(); |