ng2-bootstrap无法在angular2

时间:2017-04-01 09:17:41

标签: angular systemjs ng2-bootstrap

我正在使用angular2和ng2-bootstrap。

在我的module.ts中,我已经声明了这个

import { Ng2BootstrapModule, AlertModule } from 'ng2-bootstrap';
imports:      [ BrowserModule,
    ...,
    Ng2BootstrapModule.forRoot(),
    AlertModule.forRoot(),
    ... ]

在我的组件模板中,我已声明如下:

测试警报

我的systemjs.config.js:

map:{
  ...,
  'moment': 'npm:moment',
  'ng2-bootstrap': 'npm:ng2-bootstrap',
  ...
},
packages: {
  ...,
  'moment': { main: 'moment.js', defaultExtension: 'js' },
  'ng2-bootstrap': { format: 'cjs', main: 'bundles/ng2-bootstrap.umd.js', defaultExtension: 'js' },
  ...
}

但我收到了这个错误:

Unhandled Promise rejection: Template parse errors:
'alert' is not a known element:
1. If 'alert' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.

我失踪了什么。请帮帮我。我花了几个小时才找到解决方案,但却没有。

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果您需要datepicker和alert,请导入它们

import { DatepickerModule, AlertModule } from 'ng2-bootstrap';
imports:      [ BrowserModule,
    ...,
    DatepickerModule.forRoot(),
    AlertModule.forRoot(),

会发生什么: Angular需要导入用于渲染的模块 在相应的子模块中