0
AngularUI Datepicker가 연결되어 있으며 캘린더에서 다른 날짜를 선택하면 해당 날짜에 연결된 ISO 날짜의 시간 부분이 재설정됩니다. ngModel 속성. 어떻게 시간을 지킬 수 있도록 설정할 수 있습니까?AngularUI Datepicker가 ngModel에서 시간을 재설정합니다.
AngularUI Datepicker가 연결되어 있으며 캘린더에서 다른 날짜를 선택하면 해당 날짜에 연결된 ISO 날짜의 시간 부분이 재설정됩니다. ngModel 속성. 어떻게 시간을 지킬 수 있도록 설정할 수 있습니까?AngularUI Datepicker가 ngModel에서 시간을 재설정합니다.
지시어를 사용하여 문제를 해결했습니다.
input(ng-model="event.date_started", j-datepicker)
div(ng-model="event.date_started", j-datepicker)
.directive 'jDatepicker', ->
require: 'ngModel'
link: (scope, elem, attrs, ngModel) ->
# check if elem is an input so when the input
# gains focus it doesn't spawn another calender
if not elem.is('input')
elem.datepicker
onSelect: (dateText) ->
# get the original ISO date and new date
oldDate = new Date ngModel.$modelValue
newDate = new Date dateText
# set the new month and day onto the original ISO date
oldDate.setUTCMonth newDate.getUTCMonth()
oldDate.setUTCDate newDate.getUTCDate()
scope.$apply() ->
# update the model with the new info
ngModel.$setViewValue oldDate.toISOString()
ngModel.$render =() ->
date = new Date ngModel.$viewValue
# set the default highlighted date on the calender
elem.datepicker 'setDate', date
# this renders the date value on the
# input element in the format I want
elem.val date.toDateString()