Javascript AngularJS日期选择器未更新指令
因此,我密切关注AngularJS.org上的文档(在的Datepicker部分下),但到目前为止,当选择了新日期(默认日期除外)时,输入字段将更新,而不是指令。但是,该指令仅在手动编辑输入字段时更新。我是AngularJS的新手,但我到处都在搜索,似乎找不到这个问题的正确答案 这是我的控制器:Javascript AngularJS日期选择器未更新指令,javascript,jquery,angularjs,twitter-bootstrap,datepicker,Javascript,Jquery,Angularjs,Twitter Bootstrap,Datepicker,因此,我密切关注AngularJS.org上的文档(在的Datepicker部分下),但到目前为止,当选择了新日期(默认日期除外)时,输入字段将更新,而不是指令。但是,该指令仅在手动编辑输入字段时更新。我是AngularJS的新手,但我到处都在搜索,似乎找不到这个问题的正确答案 这是我的控制器: var QuizCntrl = function ($scope) { // Sets the default date, making adjustments for meetings that w
var QuizCntrl = function ($scope) {
// Sets the default date, making adjustments for meetings that would otherwise land on a weekend date.
$scope.date_selected = new Date();
$scope.date_selected.setHours(0,0,0,0);
if($scope.date_selected.getDay() == 3 || $scope.date_selected.getDay() == 4)
$scope.date_selected.setDate($scope.date_selected.getDate() + 5);
else
$scope.date_selected.setDate($scope.date_selected.getDate() + 3);
// Clears selection
$scope.clear = function () {
$scope.date_selected = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};
$scope.minDate = new Date();
// $scope.$watch('date_selected', function() {
// });
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 0
};
$scope.initDate = new Date('2016-15-20');
$scope.formats = ["shortDate"];
$scope.format = $scope.formats[0];
})
以下是我的观点(仅适用于日期选择器):
$scope.date\u selected=null
基本上是一个大禁忌。AngularJS的内部监视过程依赖于您保持对$scope对象的引用完好无损。您可以创建一个plunkr来处理示例吗?
<div class="jumbotron" ng-controller="QuizCntrl"">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="shortDate" ng-model="date_selected" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
{{date_selected | date:'fullDate' }}
</div>