1

我有一个角度服务,它有这样的自定义方法

appServices.factory('RuleSets', ['$resource',
    function($resource){
        return $resource('', {}, {
            query: {
                method:'GET',
                isArray:true,
                url: '../data/routing-ruleset-:ruleSetId.json'
            },
            unschedule: {
                method: 'POST',
                url: '../data/unschedule:ruleSetId.json'
            },
            schedule: {
                method: 'POST',
                params: {ruleSetId: ':ruleSetId', date: ':date'},
                url: '../data/schedule.json'
            }
        });
    }]);

我在使用自定义方法发布数据时遇到问题

RuleSets.unschedule({ruleSetId: ruleSetId});

RuleSets.schedule({date: $scope.formattedDate, ruleSetId: $scope.selectedRuleSet})

我在前者中看到的行为是,如果它是 POST 请求,则不会填充 ruleSetId url 参数。在后者中,如果它是一个发布请求,我不知道如何填充请求参数(我知道编写的代码不正确),因为我在我的服务功能中尝试过的内容不起作用。我还想将数据作为“计划”请求的一部分发送。我已经看到我可以通过说这样做来做到这一点

var ruleSets = new RuleSets();
ruleSets.id =  $scope.selectedRuleSet
ruleSets.$save();

但是我该如何使用自定义方法呢?

我应该使用 $http 还是不使用那么多自定义方法。我喜欢自定义方法提供的结构,所以如果可能的话,我想保持这种结构。

4

0 回答 0