【问题标题】:Bootstrap not working and not displaying data (Angular)Bootstrap 不工作且不显示数据(Angular)
【发布时间】:2019-01-23 23:27:00
【问题描述】:

我开始了这门 Angular 课程,但一开始就被卡住了……我通过它的指南安装了 Bootstrap,但我仍然得到空白页。

重新安装整个东西没有帮助

angular.json

"styles": [
          "src/styles.css",
          "./node_modules/bootstrap/dist/css/bootstrap.min.css"

        ],
        "scripts": [
          "node_modules/jquery/dist/jquery.slim.min.js",
          "node_modules/popper.js/dist/umd/popper.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js"
        ],

app.component.ts

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

@Component({
  selector: 'app-root',
  template: `<app-server></app-server>
              <app-server></app-server>`,
  styleUrls: ['./app.component.css',]
})
export class AppComponent {
  title = 'title';
}

app.module.ts

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


import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';
import { ServersComponent } from './servers/servers.component';
@NgModule({
  declarations: [
    AppComponent,
    ServerComponent,
    ServersComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<div class="container">
  <div class="row">
    <div class="col-xs-1-12">
      <h3>new component here</h3>
      <hr>
      <app-servers></app-servers>
    </div>
  </div>
</div>

【问题讨论】:

  • 您是否安装了引导程序:npm install bootstrap --save
  • 这个文件是否存在于你的节点模块中:./node_modules/bootstrap/dist/css/bootstrap.min.css
  • 没有错误,服务器工作正常,这是屏幕imgur.com/gHDU10k 我用 npm 安装了引导程序,是的,该文件存在于节点模块中。

标签: angular


【解决方案1】:

angular 2+ 的引导程序由 NgBootstrap 命名。您可以查看他们的页面https://ng-bootstrap.github.io/#/home

Ng bootstrap 的依赖通过安装在解决方案中插入到 package.json 中

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

如果你没有在你的机器上安装 ng-bootstrap,你需要全局安装它,然后添加 -g 标志来安装

npm install -g "@ng-bootstrap/ng-bootstrap"

然后尝试使用第一个命令重新安装

【讨论】:

    猜你喜欢
    • 2017-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-29
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多