Angular学习笔记【如何正确使用第三方组件】?

例如:ng-bootstrap的使用;

1、首先肯定是先要安装,参考官网给出的指令安装即可。(npm install --save @ng-bootstrap/ng-bootstrap)

2、在AppModule模块中引入这个组件:

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

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

3、在自己的应用程序中引入这个模块:

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

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

4、在我们自己的页面就可以正常使用了。

我刚开始,没有做第三部,所以,导致我一直无法正常使用,又仔仔细细读了一下官网文档,这才发现是这个问题,望其他同学不要犯这个错误。