css - 为什么 Bootstrap 表不使用 Angular 7 中的样式?

标签 css angular typescript bootstrap-4 angular7

我尝试在 Angular 7.2 元素中创建简单的 Bootstrap 表,但它不使用任何样式。我只看到原始文本。知道为什么它不起作用吗?

组件.ts:

elements: any = [
    {id: 1, first: 'Mark', last: 'Otto', handle: '@mdo'},
    {id: 2, first: 'Jacob', last: 'Thornton', handle: '@fat'},
    {id: 3, first: 'Larry', last: 'the Bird', handle: '@twitter'},
  ];

  headElements = ['ID', 'First', 'Last', 'Handle'];

组件.html:

<table mdbTable striped="true">
  <thead>
    <tr>
      <th *ngFor="let head of headElements" scope="col">{{head}} </th>
    </tr>
  </thead>
  <tbody>
    <tr mdbTableCol *ngFor="let el of elements">
      <th scope="row">{{el.id}}</th>
      <td>{{el.first}}</td>
      <td>{{el.last}}</td>
      <td>{{el.handle}}</td>
    </tr>
  </tbody>
</table>

angular.json:

    "styles": [
      "src/styles.scss",
      "node_modules/bootstrap/dist/css/bootstrap.min.css",
      "src/assets/sass/paper-kit.scss",
      "src/assets/css/demo.css",
      "src/assets/css/nucleo-icons.css"
    ],
    "scripts": [
      "node_modules/jquery/dist/jquery.slim.min.js",
      "node_modules/popper.js/dist/umd/popper.js",
      "node_modules/bootstrap/dist/js/bootstrap.min.js"
    ],

样式.scss:

@import "~bootstrap/dist/css/bootstrap.css";

应用程序模块.ts:

import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
...
imports: [
    ...,
    NgbModule.forRoot(),
    ...
  ],
 ...
bootstrap: [AppComponent]

最佳答案

要使用 Bootstrap 表,只需添加类 table,对于 striped,添加 table-striped

<table  class="table table-striped">
</table

但是您的 HTML 显示您使用了 mdbootstrap .你需要安装angular-bootstrap-md

npm i angular-bootstrap-md

关于css - 为什么 Bootstrap 表不使用 Angular 7 中的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57840288/

相关文章:

html - 无法使用 coreUi 显示图标

css - Safari iOS 中出现奇怪的 "filter:grayscale"错误?

css - 在表格列上实现右对齐文本的正确 CSS 方法是什么?

javascript - nestjs 应用程序的生产部署的正确方法是什么

typescript - 使用 Vue 构建 TypeScript 代码时 Webpack 构建错误

javascript - 取消 Angular 形式时撤消对模型状态的更改

html - 默认 HTML 字体大小

javascript - Angular 2 - 如何使我的 index.html 文件标题和元标签的关键字和描述动态

angular - 启用 Angular 组件以显示多个表格行而不破坏表格格式

angular - 父组件的值不会被子组件改变