【问题标题】:Angular CLI - angular 5.2.0 with ng-boostrap is not workingAngular CLI - 带有 ng-bootstrap 的 Angular 5.2.0 不起作用
【发布时间】:2018-08-04 22:46:46
【问题描述】:

我正在尝试使用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>

【问题讨论】:

  • 发布应用/页面的输出 HTML。那里正在加载 Bootstrap css 吗?
  • 似乎没有加载...但是如果您查找 ng-boostrap 它会显示:Should I add bootstrap.js or bootstrap.min.js to my project? No, the goal of ng-bootstrap is to completely replace JavaScript implementation for components. Nor should you include other dependencies like jQuery or popper.js. It is not necessary and might interfere with ng-bootstrap code.
  • css和js不一样
  • 如果您知道其中的区别,那么发布您之前的评论将毫无意义。
  • @Evilguy 标签已经存在。

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


【解决方案1】:

添加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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2017-04-12
    • 1970-01-01
    相关资源
    最近更新 更多