角度引导下拉打开左侧

时间:2016-03-07 07:16:29

标签: css angularjs twitter-bootstrap angular-bootstrap

我已成功使用角度引导下拉列表link。 但问题是下拉列表在右侧打开。 我如何让它在左边打开? 这是我在给定链接中使用的标记和js。

标记:

<div ng-controller="DropdownCtrl">
<!-- Single button with keyboard nav -->
<div class="btn-group" uib-dropdown keyboard-nav>
    <button id="simple-btn-keyboard-nav" type="button" class="btn btn-primary" uib-dropdown-toggle>
        Dropdown with keyboard navigation <span class="caret"></span>
    </button>
    <ul uib-dropdown-menu role="menu" aria-labelledby="simple-btn-keyboard-nav">
        <li role="menuitem"><a href="#">Action</a></li>
        <li role="menuitem"><a href="#">Another action</a></li>
        <li role="menuitem"><a href="#">Something else here</a></li>
        <li class="divider"></li>
        <li role="menuitem"><a href="#">Separated link</a></li>
    </ul>
</div>
</div>

JS:

angular.module('ui.bootstrap.demo').controller('DropdownCtrl', function ($scope, $log) {
$scope.items = [
'The first choice!',
'And another choice for you.',
'but wait! A third!'
];

$scope.status = {
isopen: false
};

$scope.toggled = function(open) {
$log.log('Dropdown is now: ', open);
};

$scope.toggleDropdown = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.status.isopen = !$scope.status.isopen;
};

$scope.appendToEl = angular.element(document.querySelector('#dropdown-long-content'));
});

请帮助

1 个答案:

答案 0 :(得分:60)

将班级dropdown-menu-right添加到<ul uib-dropdown-menu>

默认情况下,drowpdown打开与父项左侧对齐并向右侧增长。添加班级dropdown-menu-right后,它将在右侧打开对齐。

编辑:
Angular Bootstrap with Bootstrap 4允许使用placement属性(可能选择bottom-rightrighttop-right)对下拉列表进行更精细的放置。<登记/> 资料来源:https://ng-bootstrap.github.io/#/components/dropdown/api

Vue-Bootstrap提供right属性(布尔值) 资料来源:https://bootstrap-vue.js.org/docs/components/dropdown/#bd-content

React-bootstrap调用属性pullRight(布尔值)
资料来源:https://react-bootstrap.github.io/components/dropdowns/#btn-dropdowns-right