使用Bootstrap在Angular中下拉菜单不起作用

时间:2019-03-21 16:04:05

标签: angular bootstrap-4 dropdown

我已经使用npm并将Bootstrap 4和jquery,popper等导入到我的Angular应用程序中,但是顶部导航栏中的下拉菜单不起作用。我不想导入其他类似ng-boostrap或ngx-boostrap的Angular Bootstrap库。将Boostrap导入Angular后,为什么Bootstrap的下拉菜单不起作用?

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">successfullysell.com</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
        aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">

    <ul class="navbar-nav mr-auto">

        <li class="nav-item active">
            <a routerLink="company/create" class="nav-link" routerLinkActive="active">Create Companies</a>
        </li>

        <li class="nav-item dropdown">
            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                Dropdown
            </a>
            <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                <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>
        </li>

    </ul>

</div>

1 个答案:

答案 0 :(得分:-1)

在angular.json中,您需要在下面添加并重建。

        "styles": [
          "src/styles.scss",
          "node_modules/bootstrap/dist/css/bootstrap.min.css"
        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/popper.js/dist/umd/popper.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js"
        ],