{"id":20518371,"url":"https://github.com/jeff-tian/angular-service","last_synced_at":"2025-07-22T12:35:45.492Z","repository":{"id":57179075,"uuid":"50080574","full_name":"Jeff-Tian/angular-service","owner":"Jeff-Tian","description":"Wrap $http to handle service's 200 OK error response.","archived":false,"fork":false,"pushed_at":"2023-10-06T08:11:18.000Z","size":156,"stargazers_count":2,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-14T04:30:46.758Z","etag":null,"topics":["angular","pagination"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jeff-Tian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-01-21T03:52:23.000Z","updated_at":"2019-05-23T04:02:23.000Z","dependencies_parsed_at":"2025-04-14T00:56:11.766Z","dependency_job_id":"b155ff81-a091-43d0-88df-a992810e73f6","html_url":"https://github.com/Jeff-Tian/angular-service","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/Jeff-Tian/angular-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff-Tian%2Fangular-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff-Tian%2Fangular-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff-Tian%2Fangular-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff-Tian%2Fangular-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jeff-Tian","download_url":"https://codeload.github.com/Jeff-Tian/angular-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jeff-Tian%2Fangular-service/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266496590,"owners_count":23938714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["angular","pagination"],"created_at":"2024-11-15T21:40:26.666Z","updated_at":"2025-07-22T12:35:45.453Z","avatar_url":"https://github.com/Jeff-Tian.png","language":"JavaScript","readme":"# angular-service\nWrap $http to handle service's 200 OK error response.\nWrap pagination data to handle pageState indicated pagination data.\n\n# why use this instead of $http\nIdeally, when api rejects to service a client request, it should return an error message with http error codes such as 4xx, 5xx. But in reality there are APIs returns 200 OK http status code, but actually it fails to serve the client request. It defines another error code system instead of http status codes, so these 200 OK errors can't be caught by the $http's error callback,  in consequence you will need to write error handling code in the success callback. And that's what this angular-service comes in handy, it enables you that only need to write error handling code in error callback.\n\n# Contribution Notice:\n```\nnpm install gulp-cli -g\nnpm install gulp -D\nnpm install\ngulp\n```\nRun `gulp` before making `git commit`. So the `dist` folder will be updated.\n\n# Install\n - Via npm\n```\nnpm install angular-service\n```\n - Via bower\n```\nbower install angular-service\n```\n\n# Update \n```\nbower update angular-service\n```\n\n# Basic Usage\n```jade\nscript(src=\"#{cdn.normal}bower_components/angular/angular.min.js?#{cdn.version}\")\nscript(src=\"#{cdn.normal}bower_components/angular-service/dist/scripts/all.js?#{cdn.version}\")\n\nscript.\n    angular.module('yourModule', ['servicesModule'])\n        .controller('yourCtrl', ['service', function(service){\n            service.get('xxx', {}).then(success, fail);\n        }])\n    ;\n\n```\n\n# Pagination Usage\nThere are 2 kinds of pagination:\n    - pagination2: data was stored in cassandra or the same type of database, fetched by pageState, don't know the total records ahead of time \n    - pagination-total: data was stored in solr or the same type of database, fetched by offset, and you can get the total records ahead of time\n    \n1. pagination2\n**Screen shot:**\n![Screen shot of pagination](assets/pagination.png)\n\n**jade/pug template (Still haven't been using jade/pug? Use it, and convert your existing html to jade/pug by this tool: http://html2pug.jijiyy.me/)**\n```jade\ndiv(ng-controller=\"yourCtrl\")\n    table.ui.single.line.table\n        thead\n            tr\n                th 时间\n                th 项目\n                th 内容\n        tbody\n            tr(ng-repeat=\"record in yourDataRecords.records[yourDataRecords.pageIndex]\")\n                td\n                    span {{record.createDate | date : 'yyyy年M月d日'}}\n                    br\n                    span {{record.createDate | date: 'hh:mm'}}\n                td\n                    div(ng-repeat=\"p in record.product\") {{p.name}}\n                td.ui.middle.aligned\n                    span.middle.aligned {{record.type === 'I' ? '+' : (record.type === 'E' ? '-' : '')}}{{record.amount}}\n        tfoot\n            tr\n                th(colspan=\"3\")\n                    include ../../public/bower_components/angular-service/views/pagination2.jade\n                    + pagination2('yourDataRecords')\n```\n**javascript**\n```javascript\nangular.module('yourModule', ['servicesModule'])\n    .controller('yourCtrl', ['$scope', 'service', 'paginationData', function ($scope, service, paginationData) {\n        $scope.yourDataRecords = new paginationData('http://your/data/source/url');\n        $scope.yourDataRecords.getNextPage();\n    }])\n    .controller('anotherCtrl', ['$scope', 'service', 'paginationData', function ($scope, service, paginationData) {\n        $scope.yourDataRecords = new paginationData('http://your/data/source/url', {pageSize: 5});\n        $scope.yourDataRecords.getNextPage();\n    }])\n    .controller('yetAnotherCtrl', ['$scope', 'service', 'paginationData', function ($scope, service, paginationData) {\n        $scope.yourDataRecords = new paginationData('http://your/data/source/url');\n        $scope.yourDataRecords.getNextPage({pageSize: 15});\n    }])\n;\n```\n\n2. pagination-total\n**jade/pug template (Still haven't been using jade/pug? Use it, and convert your existing html to jade/pug by this tool: http://html2pug.jijiyy.me/)**\n```jade\ndiv(ng-controller=\"yourCtrl\")\n    table.ui.single.line.table\n        thead\n            tr\n                th 时间\n                th 项目\n                th 内容\n        tbody\n            tr(ng-repeat=\"record in yourDataRecords.records[yourDataRecords.pageIndex]\")\n                td\n                    span {{record.createDate | date : 'yyyy年M月d日'}}\n                    br\n                    span {{record.createDate | date: 'hh:mm'}}\n                td\n                    div(ng-repeat=\"p in record.product\") {{p.name}}\n                td.ui.middle.aligned\n                    span.middle.aligned {{record.type === 'I' ? '+' : (record.type === 'E' ? '-' : '')}}{{record.amount}}\n        tfoot\n            tr\n                th(colspan=\"3\")\n                    include ../../public/bower_components/angular-service/views/pagination-total.jade\n                    + paginationTotal('yourDataRecords')\n```\n**javascript**\n```javascript\nangular.module('yourModule', ['servicesModule'])\n    .controller('yourCtrl', ['$scope', 'service', 'paginationDataWithTotal', function ($scope, service, paginationDataWithTotal) {\n        $scope.yourDataRecords = new paginationDataWithTotal('http://your/data/source/url');\n        $scope.yourDataRecords.getNextPage();\n    }])\n    .controller('anotherCtrl', ['$scope', 'service', 'paginationDataWithTotal', function ($scope, service, paginationDataWithTotal) {\n        $scope.yourDataRecords = new paginationDataWithTotal('http://your/data/source/url', {pageSize: 5});\n        $scope.yourDataRecords.getNextPage();\n    }])\n    .controller('yetAnotherCtrl', ['$scope', 'service', 'paginationDataWithTotal', function ($scope, service, paginationDataWithTotal) {\n        $scope.yourDataRecords = new paginationDataWithTotal('http://your/data/source/url');\n        $scope.yourDataRecords.getNextPage({pageSize: 15});\n    }])\n;\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeff-tian%2Fangular-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjeff-tian%2Fangular-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjeff-tian%2Fangular-service/lists"}