我能够让我的时间选择器动态显示时间范围,如本帖所示:Dynamic Options for AngularJS Directive
但是,使用这种方法时,它不会在表单上提交时间。它声明在使用此功能时未定义:
<input ng-if="timeOptions" type="text" placeholder="Start Time" id="timestart" pick-a-time="timeOptions" data-ng-model="itemtimestart" class="form-control" autocomplete="off">
在我尝试动态设置时间范围之前,它有效,但使用的是指令的先前版本:
appDirectives.directive('pickATime', function() {
return {
// Restrict it to be an attribute in this case
restrict: 'A',
// responsible for registering DOM listeners as well as updating the DOM
link: function(scope, element, attrs) {
element.pickatime(scope.$eval(attrs.pickATime));
},
};
});
之前的用法如下:
<input type="text" placeholder="End Time" id="timeend" pick-a-time="{min: [0,0], max: [23,30]}" data-ng-model="itemtimeend" class="form-control" autocomplete="off">
看来ng-model在提交时没有被提取,但我不知道在哪里。我的指令目前是:
appDirectives.directive('pickATime', function() {
return {
// Restrict it to be an attribute in this case
restrict: 'A',
// responsible for registering DOM listeners as well as updating the DOM
link: function(scope, element, attrs) {
element.pickatime(scope.options());
},
scope: {
options: '&pickATime'
},
};
});
我的控制器如下:(适用于具有约束时间范围的
// Get $scope variables to control time picker range
var startHour = settingvalue.Work_x0020_Day_x0020_Start_x0020.split(":")[0];
var startMinute = settingvalue.Work_x0020_Day_x0020_Start_x0020.split(":")[1];
var endHour = settingvalue.Work_x0020_Day_x0020_End_x0020_M.split(":")[0];
var endMinute = settingvalue.Work_x0020_Day_x0020_End_x0020_M.split(":")[1];
$scope.timeOptions = { // full options listed at: http://amsul.ca/pickadate.js/time/
min: [startHour,startMinute],
max: [endHour,endMinute],
};