Last active
May 11, 2018 17:42
-
-
Save matheusmurta/479770aadae3f23dc56e53452a129577 to your computer and use it in GitHub Desktop.
Service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('meuApp').controller('userCtrl', function ({blabla..}, userService) { | |
| {...} | |
| //Exemplo | |
| userService.List().then(function (result) { | |
| vm.list = result; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| angular.module('meuApp').factory("userService", function (API_URL, $http) { | |
| {...} | |
| userService.List = function () { | |
| var promise = $http({ | |
| method: 'GET', | |
| url: API_URL.url + '/api/v1/usuario' | |
| }) | |
| .then(function (response) { | |
| return response.data.content; | |
| }, | |
| function (response) { | |
| //error action | |
| }); | |
| return promise; | |
| }; | |
| userService.getUser = function (id) { | |
| var promise = $http({ | |
| method: 'GET', | |
| url: API_URL.url + '/api/v1/usuario/' + id | |
| }) | |
| .then(function (response) { | |
| return response.data.content; | |
| }, | |
| function (response) { | |
| //error action | |
| }); | |
| return promise; | |
| }; | |
| userService.New = function (userData) { | |
| var promise = $http({ | |
| method: 'POST', | |
| url: API_URL.url + '/api/v1/usuario', | |
| data: userData | |
| }) | |
| .then(function (response) { | |
| return response.data; | |
| }, | |
| function (response) { | |
| //error action | |
| }); | |
| return promise; | |
| }; | |
| userService.Edit = function (userData, id) { | |
| var promise = $http({ | |
| method: 'PUT', | |
| url: API_URL.url + '/api/v1/usuario/' + id, | |
| data: userData | |
| }) | |
| .then(function (response) { | |
| return response.data; | |
| }, | |
| function (response) { | |
| //error action | |
| }); | |
| return promise; | |
| }; | |
| userService.Delete = function (id) { | |
| var promise = $http({ | |
| method: 'DELETE', | |
| url: API_URL.url + '/api/v1/usuario/' + id | |
| }) | |
| .then(function (response) { | |
| return response.data; | |
| }, | |
| function (response) { | |
| //error action | |
| }); | |
| return promise; | |
| }; | |
| return userService; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment