下拉菜单应该是动态填充语言列表的,我尝试使用ngFor来实现这个功能,但是除了第一个列表项之外,其他列表项都没有出现在下拉菜单中:
<nav class ="navbar navbar-light bg-light fixed-top">
<div *ngIf="data.enableLanguageList && data.languageList?.length > 0" class="row">
<div ngbDropdown class="col d-inline-block">
<button ngbDropdownToggle
class="btn btn-success btn-lg dropdown-toggle"
id="languageSelect">
<strong> Lang - {{ data.currentLanguage }} </strong>
</button>
<div ngbDropdownMenu
*ngFor="let lang of data.languageList;"
class="dropdown-menu"
aria-labelledby="languageSelect">
<button ngbDropdownItem
class="dropdown-item"
[ngClass] = "[lang === data.currentLanguage ? 'active' : '']"
(click) = "setLanguage(lang)">
<h5> <strong> {{ lang }} </strong> </h5>
</button>
</div>
</div>
</div>
</nav>
2条答案
按热度按时间py49o6xq1#
当需要在循环中创建多个
ngbDropdownItem
时,您将ngFor
应用于ngbDropdownMenu
lx0bsm1f2#
ul
,li
方法可用于ngbDropdown