我正在使用Angular UI Bootstrap Datepicker工作日期选择器。我的挑战是默认情况下将日期选择器的输入字段设置为空字段。
让我告诉你我用过的输入字段。
<td>
<div>
<input class="form-control" type="text" datepicker-popup="dd/MM/yyyy" id='txtDate' ng-model="personalDetail.date" is-open="personalDetail.isOpen" close-text="Close" ng-click="open($event, personalDetail)" name="datefilter" value="" />
</div>
</td>
我的剧本
$scope.personalDetails.forEach(function(personalDetail){
personalDetail.date = new Date(personalDetail.date);
});
$scope.open = function($event, personalDetail) {
$event.preventDefault();
$event.stopPropagation();
personalDetail.isOpen = true;
};
我在带有ng-repeat的html表中使用它。但我需要的是显示日期字段为空,直到我设置相应的日期。请帮助我。
答案 0 :(得分:3)
<td>
<div>
<input class="form-control" type="text" datepicker-popup="dd/MM/yyyy" id='txtDate' ng-model="personalDetail.date" is-open="personalDetail.isOpen" close-text="Close" ng-click="open($event, personalDetail)" name="datefilter" value="" />
</div>
</td>
你的控制器应该是
$scope.personalDetails.forEach(function(personalDetail){
//personalDetail.date = new Date(personalDetail.date);//sets the value to the control
personalDetail.date = !personalDetail.date || new Date(personalDetail.date).toISOString() == new Date('1/1/1900').toISOString()
? '' // Date is null, undeclared, or default value
: new Date(personalDetail.date);
});
$scope.open = function($event, personalDetail) {
$event.preventDefault();
$event.stopPropagation();
personalDetail.isOpen = true;
};
答案 1 :(得分:1)
从
改变 personalDetail.date = new Date(personalDetail.date);
到
personalDetail.date = "";
喜欢$scope.personalDetail={
date: ""
}