gpt4 book ai didi

angular - 如何配置 NgbDropdown 以显示下拉列表中的所选项目

转载 作者:太空狗 更新时间:2023-10-29 17:06:33 27 4
gpt4 key购买 nike

ng-bootstrap NgbDropdown ,您将如何显示所选按钮的文本,以便用户选择的任何项目都会替换最初显示的默认文本?

在下面的示例中,目标是显示用户选择的任何排序选项。

<div ngbDropdown class="d-inline-block">

<button class="btn btn-outline-primary" id="sortMenu" ngbDropdownToggle>Sort by...</button>

<div class="dropdown-menu" aria-labelledby="sortMenu">
<button class="dropdown-item">Year</button>
<button class="dropdown-item">Title</button>
<button class="dropdown-item">Author</button>
</div>

</div>

感谢您的帮助!

最佳答案

this plunkr 中展示.

示例组件:

import {Component} from '@angular/core';

@Component({
selector: 'dropdown-demo-sortby',
template: `
<div ngbDropdown class="d-inline-block">
<button class="btn btn-outline-primary" id="sortMenu" ngbDropdownToggle>{{selectedSortOrder}}</button>
<div class="dropdown-menu" aria-labelledby="sortMenu">
<button class="dropdown-item" *ngFor="let sortOrder of sortOrders" (click)="ChangeSortOrder(sortOrder)" >{{sortOrder}}</button>
</div>
</div>
`
})
export class DropdownDemoSortby {

sortOrders: string[] = ["Year", "Title", "Author"];
selectedSortOrder: string = "Sort by...";

ChangeSortOrder(newSortOrder: string) {
this.selectedSortOrder = newSortOrder;
}

}

关于angular - 如何配置 NgbDropdown 以显示下拉列表中的所选项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42170566/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com