角度CLI - 使用ng-boostrap的角度5.2.0不起作用

时间:2018-02-25 09:54:49

标签: angular bootstrap-4 angular-cli ng-bootstrap

我正在尝试使用angular cli设置角度应用程序,并且有一个专门针对角度应用的新ng-boostrap module

ng new angular-cli-bootstrap-test
cd angular-cli-bootstrap-test

npm install --save @ng-bootstrap/ng-bootstrap
ng serve

并为ng-boostrap添加了一些配置, app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { FormsModule } from '@angular/forms';

import { AppComponent } from './app.component';


@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    NgbModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  model = {
    left: true,
    middle: false,
    right: false
  };
}

app.component.html

<div class="btn-group btn-group-toggle">
  <label class="btn-primary" ngbButtonLabel>
    <input type="checkbox" ngbButton [(ngModel)]="model.left"> Left (pre-checked)
  </label>
  <label class="btn-primary" ngbButtonLabel>
    <input type="checkbox" ngbButton [(ngModel)]="model.middle"> Middle
  </label>
  <label class="btn-primary" ngbButtonLabel>
    <input type="checkbox" ngbButton [(ngModel)]="model.right"> Right
  </label>
</div>
<hr>
<pre>{{model | json}}</pre>

对不起,如果我错过了什么,一切都显示没有任何错误,但没有引导样式,也许我错过了什么?

页面源代码浏览器:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>AngularCliBootstrapTest</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
  <app-root></app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

1 个答案:

答案 0 :(得分:2)

添加css解决了我的问题,ng-boostrap manual

中没有定义
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>AngularCliBootstrapTest</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

</head>
<body>
  <app-root></app-root>
</body>
</html>