AngularJS资源 - 编码URL字符串参数作为一个数组 [英] AngularJS resource - encoding url string parameter as an array
本文介绍了AngularJS资源 - 编码URL字符串参数作为一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是从角的$资源得到这个奇怪的网址:
I'm getting this weird url from Angular's $resource:
DELETE /dashboard/api/1.0/journalEntry?0=5&1=4&10=9&11=3&12=2&13=f&14=7&15=f&16=1&17=6&18=1&19=4&2=0&20=9&21=2&22=a&23=a&3=7&4=9&5=6&6=e&7=e&8=5&9=f
当我真正期待的是:
DELETE /dashboard/api/1.0/journalEntry/540796ee5f932f7f161492aa
我已经试过了网址和服务器端似乎是工作。这是与角路由器服务的一个问题。
I've tried that URL and the server side appears to be working. It's a problem with the Angular Router Service.
下面就是我定义服务:
'use strict';
angular.module('mean.dashboard')
.factory('JournalEntry', ['$resource',
function($resource){
return $resource('dashboard/api/1.0/journalEntry/:journalEntryId/', {
journalEntryId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
]);
这就是我称之为资源控制器:
And here's the controller where I call Resource:
$scope.editDeleteRow = function(item) {
console.log(item._id);
JournalEntry.remove(item._id).$promise.then(
function(response) {
$scope.addAlert('edit', 'Deleted', 'success');
//TODO remove item from client list
$scope.groupJournalEntries();
},
function(err) {
$scope.addAlert('add', 'Error ' + err.statusText, 'danger');
console.log(err);
}
);
};
我错过了什么?
推荐答案
我在赶时间,所以我没有弄清楚这一个所有的方式。它必须是与@不工作我预期的方式。我得到它的工作定义是这样的服务:
I'm in a hurry so I didn't figure this one out all the way. It had something to do with @ not working the way I expected. I got it to work defining the service like this:
.factory('JournalEntry', ['$resource',
function($resource){
return $resource('dashboard/api/1.0/journalEntry/:journalEntryId', {
}, {
update: {
method: 'PUT'
}
});
}
]);
和调用它是这样的:
JournalEntry.remove({journalEntryId: item._id}).$promise.then(
这篇关于AngularJS资源 - 编码URL字符串参数作为一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文