twitter-bootstrap 如何在 Angular 中使用 Bootstrap 导航栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45107634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use Bootstrap Navbar in Angular
提问by INFOSYS
I am using the navbar example in bootstrap in my Angular app but the nav bar doesn't come up at all.
我在我的 Angular 应用程序的引导程序中使用导航栏示例,但导航栏根本没有出现。
Here is the navbar html
这是导航栏 html
<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Navbar</a>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<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>
</nav>
I have installed bootstrap npm install bootstrap --save
我已经安装了引导程序 npm install bootstrap --save
and in styles.css imported bootstrap @import '~bootstrap/dist/css/bootstrap.css';
并在styles.css中导入引导程序 @import '~bootstrap/dist/css/bootstrap.css';
Please help Thanks
请帮忙谢谢
回答by A.khalifa
Try this
-> install bootstrap by npm install --save bootstrap
-> in .angular-cli.json in styles add "../node_modules/bootstrap/dist/css/bootstrap.min.css",will be like this
试试这个
-> 通过 npm install --save bootstrap 安装 bootstrap -> 在 .angular-cli.json 中的样式添加"../node_modules/bootstrap/dist/css/bootstrap.min.css",将是这样的
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
or add
或添加
<script src="https://cdnjs.cloudflare.com/ajax/libs/ng2-bootstrap/x.x.x/ng2-bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
or via path <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap/dist/css/bootstrap.min.css"/??>
或通过路径 <link rel="stylesheet" type="text/css" href="../node_modules/bootstrap/dist/css/bootstrap.min.css"/??>
Hope useful for you
希望对你有用
回答by David Bradley
There is no mention of Angular versions, but shouldn't this be as simple as adding the bootstrap import to the app-components.ts or what ever component typescript file is involved? The three bootstrap related lines below.
没有提到 Angular 版本,但这不应该像将引导程序导入添加到 app-components.ts 或涉及任何组件打字稿文件一样简单吗?下面的三个 bootstrap 相关行。
And I believe this was done for me via ng add angular-bootstrap-md
我相信这是通过 ng add angular-bootstrap-md 为我完成的
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { MDBBootstrapModule } from 'angular-bootstrap-md';
import { FormsModule } from '@angular/forms';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
MDBBootstrapModule.forRoot(),
FormsModule,
MDBBootstrapModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

