简体   繁体   English

使用ng-bootstrap正确设置angular 2

[英]Properly setting up angular 2 with ng-bootstrap

As a n00b to angular and Bootstrap, and relatively new to node js, I'm trying to set up a clean base (I hope) using the webpack starter kit from here: 作为angular和Bootstrap的n00b,以及对node js而言相对较新的一种,我试图从此处使用webpack入门套件来建立一个干净的基础(我希望):

https://github.com/AngularClass/angular2-webpack-starter https://github.com/AngularClass/angular2-webpack-starter

and the official Bootstrap 4 for Angular 2 from here: https://ng-bootstrap.github.io/#/getting-started 以及来自此处的Angular 2的官方Bootstrap 4: https//ng-bootstrap.github.io/#/getting-started

So far I've just added some imports to the webapp starter kit: 到目前为止,我已经将一些导入添加到了webapp入门工具包中:

"@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.9",
"bootstrap": "^4.0.0-alpha.5",
"tslint": "^3.15.1",

Now my problem is that I have no clue whatsoever what to do with and where to put the mentioned code fragments from the ng-bootstrap install documentation: 现在我的问题是,我不知道该怎么做以及从ng-bootstrap安装文档中将提到的代码片段放在哪里:

https://ng-bootstrap.github.io/#/getting-started https://ng-bootstrap.github.io/#/getting-started

What I'm asking for is: 我要的是:

1) an explanation about what these code fragments are for, and where to put this stuff in the concrete starter kit project linked above (because I'm willing to learn, but that info is a bit too short for a n00b). 1)有关这些代码段的用途的说明,以及将这些内容放在上面链接的具体入门工具包项目中的位置(因为我愿意学习,但是对于n00b来说,该信息太短了)。

I mean, what's for example AppComponent ? 我的意思是,例如AppComponent什么? It's undefined - and I have no clue what that refers to. 它是不确定的-我不知道该指的是什么。

2) Where is now actually Bootstrap within this project? 2)现在该项目中的Bootstrap实际上在哪里?

These may be stupid questions for someone knowing theses things. 对于知道这些事情的人来说,这些可能是愚蠢的问题。 But as a newbie, I'm completely lost there at the moment. 但是作为一个新手,我现在完全迷失了。

Thanks a lot for your help in advance. 非常感谢您的提前帮助。

Copied from mentioned ng-bootstrap install docs: 从提到的ng-bootstrap安装文档复制:

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

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

Other modules in your application can simply import NgbModule : 应用程序中的其他模块可以简单地导入NgbModule

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

@NgModule({
  declarations: [OtherComponent, ...],
  imports: [NgbModule, ...]
})
export class OtherModule {
}

Look in the app.module file. 查看app.module文件。 You should see the @NgModule() AppModule . 您应该看到@NgModule() AppModule This is the AppModule posted in your example. 这是AppModule发布的AppModule You should make sure that when you add the NgbModule to the imports that you call forRoot , just like your example. 您应该确保在将NgbModule添加到调用forRoot的导入中时,就像您的示例一样。

As far as the second example, right now the entire application can be build by using only the AppModule . 就第二个示例而言,现在仅使用AppModule即可构建整个应用程序。 But as the application grows, you may want to break it up in to smaller modules, in which case for these other module, you should just add NgbModule to the imports ( without forRoot() ). 但是随着应用程序的增长,您可能需要将其分解为较小的模块,在这种情况下,对于其他模块,您只需将NgbModule添加到imports不带 forRoot() )。 forRoot() is only meant to be called when adding to the root app module. forRoot()仅在添加到根应用程序模块时被调用。 For further information on using modules, you should check out the documentation on modules 有关使用模块的更多信息,您应该查看有关模块的文档

As far as the Bootstrap goes, ng-bootstrap is only the component library, and the styling for those components is based on the actual Bootstrap CSS. 就Bootstrap而言,ng-bootstrap只是组件库,这些组件的样式基于实际的Bootstrap CSS。 You have installed Bootstrap, but you also need to add the CSS to the application. 您已经安装了Bootstrap,但是还需要将CSS添加到应用程序中。 You can try to follow all these complicated steps , but if you want to just get started, maybe it would be best just to use the CDN for right now. 您可以尝试执行所有这些复杂的步骤 ,但是,如果您只是想开始,那么最好现在就使用CDN。 In your index.html just add 在您的index.html中,只需添加

<link rel="stylesheet"
      href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" 
      integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi"
      crossorigin="anonymous">

That should be all you need to get started 那应该是您开始所需要的全部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM