我已经通过以下方式在运行 Angular 2.0.1 的项目上安装了 ng2-bootstrap:
npm install ng2-bootstrap --save
我已经这样设置我的项目:
//systemjs.config.js
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
'moment': 'node_modules/moment/moment.js',
'ng2-bootstrap/ng2-bootstrap': 'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js',
// our app is within the app folder
app: 'app',
// angular bundles
And:
// app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { Ng2BootstrapModule } from 'ng2-bootstrap/ng2-bootstrap';
import { AppComponent } from './app.component';
import { ClientModule } from './client/client.module';
@NgModule({
imports: [
Ng2BootstrapModule
],
declarations: [
AppComponent
],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],
providers: [
NotificationService,
{ provide: LocationStrategy, useClass: HashLocationStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule { }
And:
// client.module.ts
import { Ng2BootstrapModule } from 'ng2-bootstrap';
@NgModule({
imports: [
Ng2BootstrapModule
],
declarations: [
],
providers: [
]
})
export class ClientModule { }
最后:
// client-info.component.ts
import { Component, OnInit, OnDestroy } from '@angular/core';
import { AlertComponent } from 'ng2-bootstrap/ng2-bootstrap';
@Component({
selector: 'client-info',
template: `
<div >
<alert type="success">hello</alert>
</div>
`,
styleUrls: ['app/client/client.css']
})
export class ClientInfoComponent {
constructor() {
}
ngOnInit(): void { }
ngOnDestroy(): void {
}
}
但在浏览网站时出现以下错误:
未处理的 Promise 拒绝:模板解析错误:
“alert”不是已知元素:
1. 如果“alert”是 Angular 组件,则验证它是否是此 > 模块的一部分。
2. 如果“alert”是 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到该组件的 >“@NgModule.schemas”以抑制此消息。 (“
[错误->]你好
我显然在这里做错了什么,但是什么呢?