angularjsangular-daterangepicker

Selecting date gives an object, not the dates


When I select dates and apply the filter, the startDate and endDate both are objects and i can't seem to be able to get the selected days.

I have already tried to select the attributes inside of the object, but it doesn't give me a good date.

I have the following code:

CONTROLLER

$scope.datePicker = {
        date: {startDate: null, endDate: null},
        options: {
            maxSpan: {
                days: 31
            },
            maxDate: moment(),
            locale: {
                separator: '  -  ',
                format: "D/MM/YYYY"
            },
            monthNames: ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro',
                'Outubro', 'Novembro', 'Dezembro'
            ]
        }
    };

HTML

<input class="filter-select date-picker" type="text" 
                        date-range-picker
                        options="datePicker.options"
                        max="datePicker.options.maxDate"
                        ranges="datePicker.opstions.maxSpan.days"
                        ng-model="datePicker.date" />

I also have a watcher that logged the following image:

Does anyone knows how to get the the startDate and endDate values as a simple string or a Date format?


Solution

  • You can use moment to get the date with the format you expect.

    For Example:

    let startDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
    let endDate = moment($scope.datePicker.date.startDate).format("DD-MM-YYYY");
    

    To know about various date formats you can check this on moment date formats