I have a problem with the angular -strap datepicker placement field. Is there a way to make the placement attribute dynamically so that it does not overlap with the height of the window. [Bottom, top].
This is a directive inside ng-repeat.
What we get for the placement attribute with this approach is an empty string, because the placment attribute has no binding in 2 ways.
<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>
I run datepicker with this directive.
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});
});
});
};
}]);
This is a directive in which it must be dynamically changed.
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 };
};
}
};
});
source
share