angular bootstrap dropdown to open on left

Gaurav Gupta picture Gaurav Gupta · Mar 7, 2016 · Viewed 19.5k times · Source

I have used angular bootstrap dropdown successfully link. But the problem it that the dropdown opens on the right side. How can i make it to open on left? Here is the markup and js i used from the given link.

Markup:

<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'));
});

please help

Answer

tao picture tao · Mar 7, 2016

Add the class dropdown-menu-right to your <ul uib-dropdown-menu>.

By default, the drowpdown opens aligned to the left side of the parent and growing towards right side. When added the class dropdown-menu-right it will open aligned on the right side.

EDIT:
Angular Bootstrap with Bootstrap 4 allows a more fine-tuned placement of the dropdown, using the placement attribute (w/ possible choices of bottom-right, right or top-right).
Source: https://ng-bootstrap.github.io/#/components/dropdown/api

Vue-Bootstrap provides the right attribute (boolean).
Source: https://bootstrap-vue.js.org/docs/components/dropdown/#bd-content

React-bootstrap calls the attribute pullRight (boolean)
Source: https://react-bootstrap.github.io/components/dropdowns/#btn-dropdowns-right