你跑npm install --save ng2-bootstrap
後,您需要按照以下步驟 -
在Systemjs.config.js,配置NG2的自舉像這個 -
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'ng2-bootstrap': 'node_modules/ng2-bootstrap'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
'ng2-bootstrap': { main: 'ng2-bootstrap.js', defaultExtension:'js'}
};
index.html中添加這些
<script src="node_modules/ng2-bootstrap/bundles/ng2-bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
在你的組件,你可以使用像這 -
import { TAB_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
樣品實施:
import { Component } from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
import {TAB_DIRECTIVES } from 'ng2-bootstrap/ng2-bootstrap';
@Component({
selector: 'my-app',
directives: [TAB_DIRECTIVES, CORE_DIRECTIVES],
template: `<h1>My First Angular 2 App with ng2-bootstrap</h1>
<tabset>
<tab heading="Static title">Static content</tab>
<tab *ngFor="let tabz of tabs"
[heading]="tabz.title"
[active]="tabz.active"
(select)="tabz.active = true"
(deselect)="tabz.active = false"
[disabled]="tabz.disabled"
[removable]="tabz.removable"
(removed)="removeTabHandler(tabz)">
{{tabz?.content}}
</tab>
</tabset>
`
})
export class AppComponent {
public tabs:Array<any> = [
{title: 'Dynamic Title 1', content: 'Dynamic content 1'},
{title: 'Dynamic Title 2', content: 'Dynamic content 2', disabled: true},
{title: 'Dynamic Title 3', content: 'Dynamic content 3', removable: true}
];
}
注:最新NG2的自舉版本與angular2 RC4版本兼容。
看看這是否有幫助。
嘗試像這樣 - 從'ng2-bootstrap/ng2-bootstrap'導入{TAB_DIRECTIVES};' – Sanket
嘗試了這一點。在終端沒有錯誤,但重建後,這一個出現在Firebug控制檯''NetworkError:404 Not Found - http:// localhost:8443/ng2-bootstrap/ng2-bootstrap「' – edamerau
我使用最新版本的ng2並且從'ng2-bootstrap/ng2-bootstrap'導入{TAB_DIRECTIVES};對我來說工作得很好。您是否檢查node_modules文件夾是否確實包含/ng2-bootstrap/ng2-bootstrap.js和d.ts文件 –