加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular-Strap datepicker的动态放置

发布时间:2020-12-17 16:57:41 所属栏目:安全 来源:网络整理
导读:我有角度带子日期选择器放置字段的问题. 有没有办法动态制作展示位置属性,以便它不会与窗口高度重叠.[bottom,top]. 这是ng-repeat中的指令. 我们使用此方法获得的placement属性是一个空字符串,因为placment属性没有2路绑定. div class="time_status_containe
我有角度带子日期选择器放置字段的问题.
有没有办法动态制作展示位置属性,以便它不会与窗口高度重叠.[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成为一个确定正确值并返回该值的函数.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读