动态放置Angular-Strap datepicker

时间:2014-10-08 07:21:07

标签: angularjs angularjs-directive datepicker angular-strap

我对角带日期选择器放置字段有问题。 有没有办法动态制作展示位置属性,以便它不会与窗口高度重叠。[bottom,top]。

这是ng-repeat中的指令。

我们使用此方法获得的placement属性是一个空字符串,因为placment属性没有2路绑定。

<div class="time_status_container" 
     ng-right-click="calculatePosition($event)" 
     ng-blur="toggleDatepicker()" 
     tabindex="-1" 
     style="outline:none;">

  <div bs-datepicker
       template="template.html"
       container="body"
       ng-model="start_date"
       data-trigger="manual"
       bs-show="show"
       placement="{{showDatePicker.position}}"
       data-max-date="{{ project.end_date }}">
  </div>

  Show Datepicker
</div>

我用这个指令触发了datepicker。

directives
.directive('ngRightClick', ["$parse", function($parse) {
return function(scope, element, attrs) {
    var fn = $parse(attrs.ngRightClick);
    element.bind('contextmenu', function(event) {
        scope.$apply(function() {
            event.preventDefault();
            fn(scope, {$event:event});
        });
    });
};
}]);

这是应该动态更改的指令。

directives
.directive('stone', function() {
    return {
        restrict: 'E',
        replace:true,
        templateUrl: 'template.html',
        controller:function($scope){

            $scope.toggleDatepicker = function(type){
                if(type == "start"){
                    $scope.showDatePicker['start'] = true;
                    $scope.showDatePicker['end'] = false;
                }
                else if(type == "end"){
                    $scope.showDatePicker['start'] = false;
                    $scope.showDatePicker['end'] = true;
                }
                else{
                    $scope.showDatePicker['start'] = false;
                    $scope.showDatePicker['end'] = false;
                }

                console.log($scope.showDatePicker)
            };

            $scope.calculatePosition = function(e){
                var mouseTopPosition = e.clientY || e.pageY;
                var lastKnowWindowHeight = $scope.getLastKnownWindowHeight();
                var datePickerStoneHeight = $scope.getDatePickerStoneHeight;
                var position;

                if((mouseTopPosition + datePickerStoneHeight) > lastKnowWindowHeight){
                    position = "top";
                }
                else{
                    position = "bottom";
                }

                $scope.showDatePicker = { start:true,position:position };
            };
        }
    };
});

1 个答案:

答案 0 :(得分:1)

当然,让showDatePicker.position成为一个确定正确值并返回该值的函数。