自定义$resource指令


(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();


        });
})();

阅读更多
上一篇angularjs之$resource中的资源的方法
下一篇Activiti 常用操作方法大全
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭