Get Data on conditions by $resource angualrjs

后端 未结 2 850
盖世英雄少女心
盖世英雄少女心 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:18

    Update your service code...

     (function () {
         'use strict';
    
      angular
        .module('appointments')
        .factory('AppointmentsService', AppointmentsService);
    
      AppointmentsService.$inject = ['$resource'];
    
      function AppointmentsService($resource) {
        var service = {
            get: $resource('api/appointments/:appointmentId',{
               appointmentId: '@_id'
            },{
               method:'GET'
            }),
            update: $resource('api/appointments/:appointmentId',{
               appointmentId: '@_id'
            },{
               method:'PUT'
            }),
            query:$resource('api/appointments',{
               method:'GET',
               isArray:true
            })
            queryByStartDate:$resource('api/appointments/:startDate',{
               startDate: '@_startDate'
            },{
               method:'GET',
               isArray:true
            })
        }
        return service;
       }
    })();
    

    And call queryByStartDate inside controller

    var startDate = new Date(); //you can use $filter to format date
    $scope.appointments = AppointmentsService.queryByStartDate({startDate:startDate});
    

提交回复
热议问题