12

我正在使用带有Angular的 ASP.NET Core 2.0 的 JavaScript 服务并尝试集成ng-bootstrap

我安装了ng-bootstrap

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

我将其添加到webpack.config.vendor.js

...
const treeShakableModules = [
    '@angular/animations',
    '@angular/common',
    '@angular/compiler',
    '@angular/core',
    '@angular/forms',
    '@angular/http',
    '@angular/platform-browser',
    '@angular/platform-browser-dynamic',
    '@angular/router',
    '@ng-bootstrap/ng-bootstrap',  // <-- down here
    'zone.js',
];
...

我添加NgbModule到我的进口app.module.shared.ts

...
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
...
@NgModule({
    declarations: [
        AppComponent,
        ...
    ],
    imports: [
        CommonModule,
        NgbModule.forRoot(),  // <-- this guy
        HttpModule,
        FormsModule,
        RouterModule.forRoot([
            ...
        ])
    ]
})
export class AppModuleShared {
}

我清理解决方案并运行:

c:\...>webpack && webpack --config webpack.config.vendor.js

一切都很好。

跑步:

c:\...>dotnet run

尝试加载页面会导致以下错误:

NodeInvocationException:预渲染在 30000 毫秒后超时,因为“ClientApp/dist/main-server”中的引导函数返回了一个未解析或拒绝的承诺。

这显然与预渲染有关。所以我目前正在尝试创建一个ng-bootstrap仅使用我想要使用的组件的模型,它不会调用任何承诺(或将使用立即解析的虚拟承诺),并且不会调用 DOM。这将被导入app.module.server.ts...

import { NgbModule } from './components/ng-bootstrap-mockup/ng-bootstrap'

...和标准...

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

...将在 中使用app.module.browser.ts,而不是中使用标准app.module.shared.ts

当然,这些都将在各自的app模块中导入......

@NgModule({
    ...
    imports: [
        NgbModule.forRoot(),
        ...
    ]
})
...

所以我的问题是,我错过了什么吗?除了像我上面描述的那样创建一个模型之外,还有更好的方法来处理这个问题吗?

4

1 回答 1

1

您可以将 Bootstrap 4 添加到 Angular 项目中

使用 NPM 安装 bootstrap Alpha 版本:

npm install --save bootstrap@4.0.0-alpha.6
//We chose a specific version to ensure future releases doesn’t break the sample. Optionally, run the following command to install the latest pre-release package.

npm install –save bootstrap@next
//Once the package is downloaded, add Bootstrap references in .angular-cli.json.

//Modify styles configuration to add Bootstrap CSS

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

//Modify scripts configuration to add jQuery, Bootstrap and Tether JS files.

"scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/tether/dist/js/tether.min.js",        
    "../node_modules/bootstrap/dist/js/bootstrap.min.js"
],
于 2017-10-14T11:58:07.570 回答