【发布时间】:2016-10-31 14:33:32
【问题描述】:
如果我尝试搜索特定的非 ID 字段,我正在使用的 API 需要非标准的 where 子句。我需要的端点是:
http://127.0.0.1:4001/api/testusers/findOne?userName=Anton
所以这将在 testusers 表中找到我的第一条记录,其列 (userName) = 'Anton'。
我的标准服务是:
angular.
module('shared.testUser').
factory('TestUser', ['$resource',
function($resource) {
return $resource('http://127.0.0.1:4001/api/testusers/:id', {id:'@id'},//parameters
{
update: {
method: 'PUT' // To send the HTTP Put request when calling this custom update method.
}
});
}
]);
我的调用函数是:
self.checkUsersEntryDirection = function(){ //NOT WORKING
self.testuser = TestUser.get({ username: 'anton' }, function() {
console.log(angular.toJson(self.testuser));
}); // get() returns a single entry
}
显然这不起作用,我不能使用标准的 get 方法。谁能想到这是如何实现的?
【问题讨论】: