ng-bootstrap中的同一页面上是否有下拉菜单和下拉菜单选项?
我已经尝试了ng-bootstrap的documentation中给出的以下代码。但这是下拉菜单的全局配置。 我希望下拉菜单和下拉菜单在同一页面上。我正在使用Angular 8。
import {Component} from '@angular/core';
import {NgbDropdownConfig} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'ngbd-dropdown-config',
templateUrl: './dropdown-config.html',
providers: [NgbDropdownConfig] // add NgbDropdownConfig to the component providers
})
export class NgbdDropdownConfig {
constructor(config: NgbDropdownConfig) {
// customize default values of dropdowns used by this component tree
config.placement = 'top-left';
config.autoClose = false;
}
}
<div ngbDropdown>
<button class="btn btn-secondary" type="button" id="dropDownMenuButton" ngbDropdownToggle>
Dropup Menu
</button>
<div class="dropdown-menu tx-13" ngbDropdownMenu aria-labelledby="dropDownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
<div class="dropup" ngbDropdown>
<button class="btn btn-secondary" type="button" id="dropupMenuButton" ngbDropdownToggle>
Dropup Menu
</button>
<div class="dropdown-menu tx-13" ngbDropdownMenu aria-labelledby="dropupMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
答案 0 :(得分:1)
看看API。
您也可以像这样直接将放置位置设置为NgbDropdown
指令
<div class="dropup" ngbDropdown placement="top-left">
...
</div>
这是NgBootstrap定位的nice guide,您可以找到更多示例。