Created
January 24, 2017 23:53
-
-
Save cristoferdomingues/b6c24df39fd8eee499e871c364b5b18e to your computer and use it in GitHub Desktop.
Angular Generic Crud
This file contains 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
'use strict'; | |
var crudService = angular.module('crud.service', ['app.config', 'ngResource']); | |
crudService.factory('CrudService', function(ENV, $resource, $schemaFormWrapper) { | |
return $resource( | |
ENV.apiEndpoint + '/senha/:crud/:entity/:param', { | |
crud: '@crud', | |
entity: '@entity', | |
param: '@param' | |
}, | |
{ | |
'get': { method: 'GET' }, | |
'save': { method: 'POST' }, | |
'update': { method: 'PUT' }, | |
'query': { | |
method: 'GET', | |
isArray: true, | |
params: { crud: this.crud || 'genericcrud' }, | |
transformResponse: function(data,header) { | |
var json = JSON.parse(data); | |
var array = json.listData; | |
return array; | |
}, | |
transformRequest : function(data,header) { | |
debugger; | |
} | |
}, | |
'remove': { method: 'DELETE' }, | |
'loadJson': { method: 'GET', | |
transformResponse: function(data,header) { | |
return $schemaFormWrapper.translater(data); | |
} | |
} | |
} | |
); | |
}).config(function($httpProvider) { | |
$httpProvider.defaults.headers.post['Content-Type'] = 'application/json; charset=UTF-8'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
CrudService.query({entity:'cadsenhacategoria'}, function (cadSenhaCategoriaRetorno) {}); -------------------------------- default
CrudService.query({crud: 'crud', entity:'cadsenhacategoria'}, function (cadSenhaCategoriaRetorno) {}); -------------------------------- especifico