我正在使用 $resource 服务进行增删改查操作,现在我想获取诸如开始日期为今天的约会之类的条件的数据。我正在通过以下方式获取所有数据
vm.appointments = AppointmentsService.query();
我的服务代码是
(function () {
'use strict';
angular
.module('appointments')
.factory('AppointmentsService', AppointmentsService);
AppointmentsService.$inject = ['$resource'];
function AppointmentsService($resource) {
return $resource('api/appointments/:appointmentId', {
appointmentId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
})();
现在我可以在这个代码块中给出条件吗AppointmentsService.query({condition});
或者在 Node Rest API 中更改我的服务。
如果是,那么我的 AppointmentsService.query 调用是什么
对于不同的 url 路径,您可以创建如下所示的新方法,或者可以将 startDate 作为查询字符串传递
控制器 :
对于路径参数
vm.appointments = AppointmentsService.searchByDate({date:'03/30/2016'});
对于查询参数
vm.appointments = AppointmentsService.searchByDate({StartDate:'03/01/2016',EndDate:'03/30/2016'});
Service:
function AppointmentsService($resource) {
return $resource('api/appointments/:appointmentId', {
appointmentId: '@_id'
}, {
update: {
method: 'PUT'
},
// For Path Param
searchByDate :{
method : 'GET',
url : 'your url/:date'
},
// For Query Param
searchByDate :{
method : 'GET',
url : 'your url/:startDate/:endDate' ,
params : { startDate : '@StartDate', endDate : '@EndDate' }
}
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)