使用 ng-bootstrap 和 angular-cli 1.0.0-beta.18

Using ng-bootstrap with angular-cli 1.0.0-beta.18

我正在使用 angular-cli 1.0.0-beta。 18 并尝试使用 https://ng-bootstrap.github.io/#/getting-started

处的指南加载 ng-bootstrap

步骤:

使用

安装 ng-bootstrap
npm install --save @ng-bootstrap/ng-bootstrap

将以下内容添加到 app.module.ts

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

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

对于我的 ibox-tools.module.ts 我有

import {NgModule} from "@angular/core";
import {BrowserModule} from "@angular/platform-browser";
import {IboxToolsComponent} from "./ibox-tools.component.ts";
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';

@NgModule({
    declarations: [IboxToolsComponent],
    imports     : [NgbModule, BrowserModule],
    exports     : [IboxToolsComponent],
})

export class IboxToolsModule {}

然后我尝试在我的 ibox 中使用 ngbDropdown 模块-tools.template.html

<div class="col-xs-6">
        <div ngbDropdown class="d-inline-block">
            <button class="btn btn-outline-primary" id="dropdownMenu1" ngbDropdownToggle>Toggle dropdown</button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenu1">
                <button class="dropdown-item">Action - 1</button>
                <button class="dropdown-item">Another Action</button>
                <button class="dropdown-item">Something else is here</button>
            </div>
        </div>
    </div>

但是 ngbDropdown 不起作用。我没有收到任何错误,包括 bootstrap4.css 等

入门指南告诉我使用

map: {
  '@ng-bootstrap/ng-bootstrap': 'node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
}

如果我使用 SystemJS,但我认为情况并非如此,因为 angular-cli 1.0.0-beta。 18 正在使用 Webpack,应该会自动加载 ng-bootstrap。我错了吗?我没有找到我应该添加映射的任何地方,其他任何人都设法将 ng-bootstrap 与 angular-cli 1.0.0-beta 一起使用。 18?

对不起,我的错。我仍在学习 angular2,问题是我将 ibox-tools.component.ts 包含在另一个模块中,而不是 ibox-tools.module[=18= .ts 是必需的,所以我错过了在 ibox-tools.module.ts 中导入的辅助模块的 ng-bootstrap ;)

所以 webpack 工作得很好,不需要像 systemjs 那样的映射。

希望你能理解我的回答,如果不明白,我会尽力解释得更好。