这是我的HTML
代码,具有引导程序类,并在Angular
中使用,此处dropdown
不会扩展,值保存数据和提取数据未显示在浏览器中。但是,如果我在任何在线引导工作区中使用相同的代码,它就可以正常工作(例如W3schools)。这里有些东西不支持它。我不明白我在这里想念的是什么。谁能帮我解决这个问题?
<ul class="nav navbar-nav navbar-right">
<li class="dropdown open">
<a class="dropdown-toggle" role="button" href="#">Manage <span class="caret"></span></a>
<ul class="dropdown-menu">
<li > <a href="#"> Save Data</a></li>
<li> <a href="#"> Fetch Data</a></li>
</ul>
</li>
</ul>
我已经在文件angular.json文件中添加了Bootstrap CSS,如下所示,
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
我正在使用Bootstrap
v4.1.2。
答案 0 :(得分:0)
您想制作一个header.component.html
文件,在其中可以放置徽标和nav
链接,其中包括 Manage , 保存数据 和 获取数据 ...我认为您要完成的工作是这样的:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a routerLink="/" class="navbar-brand">Your App Name</a>
</div>
<div class="navbar-default">
<ul class="nav navbar-nav">
<li routerLinkActive="active">
<a routerLink="/recipes">Recipes</a>
</li>
<li routerLinkActive="active">
<a routerLink="/shopping-list">Shopping List</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<ng-template [ngIf]="!authService.isAuthenticated()">
<li><a routerLink="/signin">Sign In</a></li>
<li><a routerLink="/signup">Sign Up</a></li>
</ng-template>
<li *ngIf="authService.isAuthenticated()"><a style="cursor: pointer;" (click)="onLogout()">Sign Out</a></li>
<li appDropdown class="dropdown" *ngIf="authService.isAuthenticated()">
<a class="dropdown-toggle" role="button" style="cursor: pointer;">Manage <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a style="cursor: pointer;" (click)="onSaveData()">Save Data</a></li>
<li><a style="cursor: pointer;" (click)="onFetchData()">Fetch Data</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
在此代码下,您可以找到一个简单的 Bootstrap 4
实现:
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Simple Example!</title>
</head>
<body>
<!-- Large button groups (default and split) -->
<div class="btn-group">
<button class="btn btn-success btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Save Data
</button>
<div class="dropdown-menu">
...
</div>
</div>
<div class="btn-group">
<button class="btn btn-info btn-lg dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Fetch Data
</button>
<div class="dropdown-menu">
...
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>