Get Data on conditions by $resource angualrjs

后端 未结 2 868
盖世英雄少女心
盖世英雄少女心 2021-01-25 20:43

I am using $resource service for my crud operations now i want to get data on a condition like get appointments whose starting date is today. I am fetching all data by

2条回答
  •  灰色年华
    2021-01-25 21:28

    For your different url path, you can create new method like below or you can pass startDate as a query string

    Controller :

    For Path Param

     vm.appointments = AppointmentsService.searchByDate({date:'03/30/2016'});
    

    For Query Param

    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' } 
          }
        });
      }
    

提交回复
热议问题