【发布时间】:2015-09-04 13:33:25
【问题描述】:
技术: AngularJs 和 Bootstrap-ui
环境: 我使用由“FilterCtrl”控制的可协作过滤器部分。过滤器中的每个输入元素都由嵌套控制器控制,例如“TypeaheadCtrl”或“DatepickerCtrl”。每一个的 ng-model 都在 FilterCtrl 中绑定了“$parent.field”。
问题: Datepicker 工作正常,exept,这就是问题,它没有关闭。根据默认设置 (https://angular-ui.github.io/bootstrap/#/datepicker),日期选择器应在选择日期时关闭。它不是。即使我单击按钮栏的“关闭”按钮,它也不会。如果焦点发生变化,它会关闭。
HTML:
<div class="" ng-controller="FilterCtrl">
<a class="black bold nodecoration" ng-click="isCollapsed = !isCollapsed" role="button">Filter</a>
<!-- Filter -->
<div class="bckgrnd-lgrey bordered max-width" collapse="isCollapsed" id="findenFilter">
<div class="nobreak" ng-controller="TypeaheadCtrl">
<label>Suchbegriff:
<input ng-model="$parent.searchText" placeholder="z.B. Rock" type="text" typeahead="prediction for prediction in predictions | filter:$viewValue |limitTo:8"></label>
</div>
<div class="nobreak" ng-controller="DatepickerCtrl">
<label>Datum:
<input class="" close-text="Close" datepicker-popup="{{format}}" is-open="status.opened" ng-click="open()" ng-model="$parent.selectedDate" show-weeks="false" type="text">
</div>
<div class="nobreak">
<label>Land: </label>
</div>
<button type="button" name="button" ng-click="printValues()">log values</button>
</div>
</div>
JS: DatepickerCtrl:
angular.module('tbdApp')
.controller('DatepickerCtrl', function($scope) {
this.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
$scope.today = function() {
$scope.selectedDate = new Date();
};
$scope.clear = function() {
$scope.selectedDate = null;
};
$scope.open = function($event) {
$scope.status.opened = true;
};
$scope.status = {
opened: false
};
$scope.formats = ['dd.MM.yyyy', 'dd-MMMM-yyyy', 'yyyy/MM/dd'];
$scope.format = $scope.formats[0];
$scope.today();
});
过滤控制:
angular.module('tbdApp')
.controller('FilterCtrl', function ($scope) {
this.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'Karma'
];
$scope.isCollapsed = false;
$scope.selectedDate = null;
$scope.searchText = null;
$scope.printValues = function () {
console.log("collapsed: " + $scope.isCollapsed);
console.log("selectedDate: " + $scope.selectedDate);
console.log("searchText: " + $scope.searchText);
}
});
我没有找到有类似问题的人。我想这可能是一个范围问题,但我不知道这个问题到底是什么。
【问题讨论】:
-
我不能发布两个以上的链接:') 所以这是最后一部分:当我点击“关闭”时,应该调用github.com/angular-ui/bootstrap/blob/master/template/datepicker/… 中的“close()”。 github.com/angular-ui/bootstrap/blob/master/src/datepicker/… 或者当我选择一个日期时,它应该调用github.com/angular-ui/bootstrap/blob/master/src/datepicker/…
-
尝试使用您的代码在 plunkr 中创建一个示例。我们会更容易为您提供帮助。
-
好的,我知道了。它令人难以置信的丑陋,但与原始版本一样好用 - 有点但不是 100%。享受:plnkr.co/edit/wxNULyM3TVZ03oDLSnce?p=preview PS:Collabse 在 plunkr 示例中不起作用。但这不是解决问题的必要条件。
标签: angularjs datepicker angular-ui-bootstrap