angularJs $resource自定義方法(待完善)

配置CompanyServicehtml

 1 var services = angular.module('liaoyuan.services');
 2 
 3 services.factory('CompanyService', function ($resource, baseApiUrl) {
 4     return $resource(baseApiUrl, {}, {
 5         query: {
 6             method: "GET",
 7             url: baseApiUrl + 'companys/:pageIndex1/:pageSize1',
 8             params: {},
 9             isArray: false
10         },
11         create: { method: "POST" },
12         get: { method: "GET", url: baseApiUrl + "companys/?id=:id" },
13         remove: { method: "DELETE", url: baseApiUrl + "companys/?id=:id" },
14         update: { method: "PUT", url: baseApiUrl + 'companys/?id=:id' }
15     })
16 });
 method 請求後臺的http方法;

params 參數;
isArray 是否以數組的方式返回,這裏不對,前臺會報錯誤 [$resource:badcfg]

CompanyController數組

 1 app.controller('CompanyListController', function ($scope, CompanyService, FilterService, $uibModal) {
 2     $scope.FilterService = FilterService;
 3 
 4     $scope.page = {
 5         "pageIndex": 1, "pageSize": 10, "totalCount": 0
 6     };
 7     
 8     var queryArgs = {
 9         pageIndex1: $scope.page.pageIndex,
10         pageSize1: $scope.page.pageSize
11     };
12 
13     CompanyService.query(queryArgs).$promise.then(function (result) {
14         $scope.companys = result.data;
15         $scope.page.totalCount = result.totalCount;
16     }, function (result) { //若是失敗
17         console.log('fail');
18     });
19      
20 
21 //詳情頁彈窗
22     $scope.detail = function (com,size) {
23         var uibModalInstance = $uibModal.open({
24             templateUrl: '/views/biz/company/detailModal.html',
25             controller: 'CompanyDetailsController',//爲$modal指定的控制器,初始化$scope,該控制器可用$modalInstance注入
26             size: size,
27             backdrop: 'static',
28             keyboard: false,
29             //scope:,//一個做用域爲模態的內容使用(事實上,$modal會建立一個當前做用域的子做用域)默認爲$rootScope
30             resolve: {
31                 company: function () { return com; }
32             },//定義一個成員並將他傳遞給$modal指定的控制器,至關於routes的一個reslove屬性,若是須要傳遞一個objec對象,須要使用angular.copy()
33             //windowClass:,//指定一個class並被添加到模態窗口中
34         });
35     };
36 
37   
38 });
相關文章
相關標籤/搜索