在angular ui引导程序中设置日期选择器选项
Setting options to datepicker in angular-ui bootstrap
我正在尝试使用angular ui bootstrap库中的日期选择器组件,如下所述:http://angular-ui.github.io/bootstrap/我尝试为弹出式选择器设置选项,根据文档,我应该使用datepicker-options属性将datepicker的选项传递为JSON。
在我看来,我有:
<div class="row">
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
在我的控制器中,我有:
$scope.dateOptions = {'show-button-bar': 'false', 'close-text':'SomeText'};
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.showWeeks = false;
$scope.clear = function () {
$scope.dt = null;
};
$scope.toggleMin = function() {
$scope.minDate = ( $scope.minDate ) ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
'year-format': "'yy'",
'starting-day': 1
};
$scope.format = 'dd/MM/yyyy'
正如你在一开始看到的,我试图设置选项:
$scope.dateOptions = {'show-button-bar': 'false', 'close-text':'SomeText'};
然而,它似乎不起作用,日期选择器没有改变。你知道我做错了什么吗?
我找到了解决方案,我把选项作为属性,例如:
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min="minDate" max="'2014-12-31'" datepickerOptions="dateOptions" ng-required="true" show-button-bar="false"/>
所以我把show按钮栏作为属性,而不是传递给datepickerOptions的对象的一部分。
您使用的是带短划线的选项名称。只有将这些短划线大小写的名称用作元素的单个属性时,才需要这些名称。即
<input type="text" datepicker-popup="{{format}}" starting-day="1" ng-model="dt" >
然而,datepicker-options
希望json中的命名选项具有camelBased格式,如下所示:
datepicker-options="{startingDay: 1, yearFormat: 'yy'}"
<input type="text" datepicker-popup="{{format}}"
datepicker-options="{startingDay: 1, yearFormat: 'yy'}" ng-model="dt" >
或
$scope.options = {
'startingDay': 1,
'yearFormat': 'yy'
}
<input type="text" datepicker-popup="{{format}}"
datepicker-options="{{options}}" ng-
属性starting-day="1"
也应该适用于日期选择器输入,如中所述https://angular-ui.github.io/bootstrap/#/datepicker,但我似乎无法做到这一点(使用版本0.12.1)
我知道这是一个老问题,但我想我应该指出你可能在哪里遇到了麻烦。
在控制器中,您将两次分配给$scope.dateOptions
,因此会覆盖您的第一次分配。
所以你最初的任务是:
$scope.dateOptions = {'show-button-bar': 'false', 'close-text':'SomeText'};
在接近尾声时被覆盖:
$scope.dateOptions = {
'year-format': "'yy'",
'starting-day': 1
};
根据datePicker文档,弹出设置可以通过datepickerPopupConfig全局配置,因此您必须将其添加到控制器中。
yourApp.controller('YourController', function ($scope, datepickerPopupConfig) {
datepickerPopupConfig.showButtonBar = true;
datepickerPopupConfig.closeText = 'I am done';
datepickerPopupConfig.clearText = 'Wipe it out';
}
由于某些原因,设置closeText
不起作用。我不知道为什么。
Plunker游戏示例。
日期选择器选项在0.11版本中引入,因此请确保您使用的是angular ui引导程序版本0.11或更高版本的
看起来您的dateOptions
对象键不是基于骆驼的。试试这个:
$scope.dateOptions = {
'showButtonBar': 'false',
'closeText':'SomeText'
};
Html属性应为破折号大小写,如show-button-bar
或close-text
等。
请注意datepicker-options
html属性和datepickerOptions
javascript对象之间的差异。
只需在输入中提供关闭文本、当前文本和明文属性:)
<input type="text" uib-datepicker-popup ng-model="dt" is-open="popup2.isopen" datepicker-options="dateOptions" ng-required="true" close-text="your close text here" current-text="Your current text here (today for example)" clear-text="Your clear-text here"/>
该网站的示例非常少。对我来说,在1.1.1版本中,我将配置对象作为attrib传递:
datepicker-options="datepickerOptions"
并且在控制器中,能够设置一些选项:
$scope.datepickerOptions = {
formatYear: 'yy',
startingDay: 0,
showWeeks: false
};
但是"showButtonBar"不配合,所以在代码中我看到了"uibDatepickerPopupConfig"。我把它传进来,然后单独设置,它就起作用了:
.controller('DatepickerCtrl', function ($scope, uibDatepickerPopupConfig){
uibDatepickerPopupConfig.showButtonBar = false;
使用"datepickerPopupConfig",我得到提供程序错误:
Unknown provider: datepickerPopupConfigProvider <- datepickerPopupConfig
- jquery日期选择器年份范围默认值
- jquery日期选择器失去了交互性
- 正在搜索JavaScript日期选择器滑块
- 如何在多个jQueryUI日期选择器中屏蔽特定日期
- jquery日期选择器显示与值不同的文本
- JQuery UI日期选择器:在选择出发日期时自动弹出返回日期
- Angular UI启动日期选择器问题
- 奇怪的日期选择器行为,与模糊有关
- 我希望这个日期选择器可以从1990年到2000年之间的年份中选择日期
- keith wood日期选择器日期格式和语言
- 在日期更改后更新Angular UI引导程序日期选择器选项
- Jquery UI日期选择器不关注输入
- Javascript两个日期选择器冲突
- 动态添加的标记不会'无法正确使用日期选择器
- 日期选择器无法使用javascript显示
- AngularJS自定义日期选择器指令
- 他们网站上的代码出现启动日期选择器错误
- 从第一个日期选择器定义第二个日期选择器的开始日期
- 更改日期选择器格式
- 带有推特助推器的日期选择器出现了,但没有't更改日期