关闭

自定义$resource指令

121人阅读 评论(0) 收藏 举报


(function () {
    'use strict';
    angular.module('app')
        .factory('resourceFactory',['$resource',
        function resourceFactory($resource){
            return $resource('URL',{},
                {charge:{
                    method:'POST',
                    params:{
                            crossOrigin:'Anonymous',
                            userName:'QD100'
                    },
                    isArray:false,
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                    },
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    }
                   }
                });
        }
    ]).controller('myCtrl', function ($scope, $rootScope, $state, resourceFactory) {
        $scope.loginJump = function(info) {
            resourceFactory.save(
                {
                    userName: info.staffID,
                    userPass: info.password,
                    crossOrigin: info.security
                },
                function () {
                    console.log('post sent');
                }
            );
        }
     })
        .controller('myCtrl2',function($scope, $rootScope, $state, $resource){
            // 初始化数据
            $scope.baseURL = baseURL;
            var resource = $resource(baseURL + "/mobile/:className:methodNmae.:type",
                {
                    jsessionid: '@jsessionid',
                    className: '@className',
                    methodNmae: '@methodNmae',
                    type: '@type',
                    user_id: '@user_id'
                }, {
                    initiatGroup: {
                        method: 'GET',
                        isArray: true,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                        }
                    },initiatProcessApply: {
                        method: 'POST',
                        params:{
                            oaFeedBackId:'@oaFeedBackId'
                        },
                        isArray: false,
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                        }
                    }
                });

            var initiatGroup = function () {
                resource.initiatGroup(
                    {
                        jsessionid: jsessionid,
                        user_id:user_id,
                        className: "FeedBackServiceAction_",
                        methodNmae: "getGroups",
                        type: "do",
                    },function (objs) {
                        //to do something
                    });
            };

            // 初始化方法
            var init = function() {
                initiatGroup();
            }
            init();


        });
})();

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:10659次
    • 积分:258
    • 等级:
    • 排名:千里之外
    • 原创:8篇
    • 转载:49篇
    • 译文:0篇
    • 评论:0条