angularjs – Angular-Strap datepicker的动态放置

前端之家收集整理的这篇文章主要介绍了angularjs – Angular-Strap datepicker的动态放置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_301_0@
@H_301_0@
我有角度带子日期选择器放置字段的问题.
有没有办法动态制作展示位置属性,以便它不会与窗口高度重叠.[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 };
            };
        }
    };
});

解决方法

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

猜你在找的Angularjs相关文章