【问题标题】:ng2-bootstrap module issueng2-bootstrap 模块问题
【发布时间】:2017-06-29 01:21:18
【问题描述】:

我的 Angular 2 应用程序中有 2 个模块,它是使用 Angular-Cli 创建的。 (版本 1.0.0-beta.28.3) 软件包由“npm install ng2-bootstrap@latest bootstrap@latest --save”安装(不确定我是否遗漏了什么) ng2-bootstrap 和 bootstrap 包是最新版本。 当我在 app.module.ts 中导入 ng2-directive 时,一切正常。但是,我尝试在嵌套模块中使用它,没有出现任何内容。

明确地说:

import { InModule } from './in.module';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AccordionModule } from 'ng2-bootstrap';

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

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

我可以在 appcomponent 上使用手风琴。 但是,当我尝试在 CompComponent 中将其用作以下内容时:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AlertModule } from 'ng2-bootstrap';

import { CompComponent } from './comp/comp.component';

@NgModule({
  declarations: [
      CompComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AlertModule.forRoot() // or just AlertModule
  ],
  providers: [],
  bootstrap: []
})
export class InModule { }

我得到了白屏。

我不确定这是问题还是我的错误。

【问题讨论】:

  • 你有什么错误吗?
  • 不,控制台上一切正常
  • 你也有路由吗?如果你在路由中启用跟踪,看看你是否有路由问题。
  • 不,我在新应用中尝试过,app.component.html 中只有一行:'

标签: angular module ng2-bootstrap


【解决方案1】:

您是否将引导 css 添加到您的 angular-cli.json 中。您仍然需要加载 css

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

【讨论】:

  • 我刚刚意识到我遇到了类似的问题并最终转向 ng-bootstrap,因为我花了太多时间让它工作......你只需导入这个模块整个应用程序中的东西,它无处不在......和它的 BS4 .. 以及它由那些做原始 angular ui-bootstrap 的人
猜你喜欢
  • 2017-05-22
  • 2016-06-22
  • 2017-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
相关资源
最近更新 更多