SHOW:
|
|
- or go back to the newest paste.
1 | app.service("modelService",[ "$http", function($http) { | |
2 | var model = linksharemodel; | |
3 | var insertVote = function(vote) { | |
4 | $http.post("CampusRandomLinks/CampusRandomLinks/InsertVote", | |
5 | { 'vote': vote }). | |
6 | success(function(data, status, headers, config) { | |
7 | // this callback will be called asynchronously | |
8 | // when the response is available | |
9 | model = data; | |
10 | for(var i = 0; i < updateCallbacks.length; i++) { | |
11 | updateCallbacks[i](data); | |
12 | } | |
13 | }). | |
14 | error(function(data, status, headers, config) { | |
15 | // called asynchronously if an error occurs | |
16 | // or server returns response with an error status. | |
17 | }); | |
18 | }; | |
19 | ||
20 | var updateCallbacks = []; | |
21 | ||
22 | var addUpdateCallback = function(f) { | |
23 | updateCallbacks.push(f); | |
24 | }; | |
25 | ||
26 | var get = function() { | |
27 | return model; | |
28 | }; | |
29 | ||
30 | return { | |
31 | insertVote: insertVote, | |
32 | get: get, | |
33 | addUpdateCallback: addUpdateCallback | |
34 | }; | |
35 | }]); |