Bootstrap (またはその他の) コンポーネント ライブラリの使用方法 クリストファー · 6分前
ブートストラップ コンポーネントを含める方法に関するサンプル コードを手伝ってくれる人はいますか
ブートストラップ アラートを使用しようとしています。npm パッケージをインストールし、パッケージを次のように追加しました。
アラート-component.ts:
import {Component} from '@angular/core';
import {CORE_DIRECTIVES} from '@angular/common';
import { AlertComponent } from 'ng2-bootstrap/ng2-bootstrap';
@Component({
selector: 'alert-demo',
template: `
<alert *ngFor="let alert of alerts;let i = index" [type]="alert.type" dismissible="true" (close)="closeAlert(i)">
{{ alert?.msg }}
</alert>
<alert dismissOnTimeout="3000">This alert will dismiss in 3s</alert>
<button type="button" class='btn btn-primary' (click)="addAlert()">Add Alert</button>
`,
directives: [AlertComponent, CORE_DIRECTIVES]
})
export class AlertDemoComponent {
public alerts:Array<Object> = [
{
type: 'danger',
msg: 'Oh snap! Change a few things up and try submitting again.'
},
{
type: 'success',
msg: 'Well done! You successfully read this important alert message.',
closable: true
}
];
public closeAlert(i:number):void {
this.alerts.splice(i, 1);
}
public addAlert():void {
this.alerts.push({msg: 'Another alert!', type: 'warning', closable: true});
}
}
app.component.ts
import { Component } from '@angular/core';
import { Routes, ROUTER_DIRECTIVES } from "@angular/router";
import { MessagesComponent } from "./messages/messages.component";
import { AuthenticationComponent } from "./auth/authentication.component";
import {NavBarComponent} from "./navbar.component"
import {AlertDemoComponent} from "./alert.component"
@Component({
selector: 'my-app',
template: `
<navbar></navbar>
<alert-demo></alert-demo>
`,
directives: [ROUTER_DIRECTIVES, NavBarComponent,AlertDemoComponent]
})
@Routes([
{path: '/', component: MessagesComponent},
{path: '/auth', component: AuthenticationComponent}
])
export class AppComponent {}
systemjs.config.js
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'js/app', // 'dist',
'rxjs': 'js/vendor/rxjs',
'@angular': 'js/vendor/@angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'boot.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
"node_modules/ng2-bootstrap": {defaultExtension: 'js'}
};
var paths= {
"ng2-bootstrap/ng2-bootstrap": "node_modules/ng2-bootstrap/ng2-bootstrap"
}
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/testing',
'@angular/upgrade',
'ng2-bootstrap'
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
map: map,
packages: packages,
paths: paths
};
// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }
System.config(config);
})(this);
エラーが発生しています
"NetworkError: 404 Not Found - http://localhost:3000/ng2-bootstrap/ng2-bootstrap"
ng2-bootstrap
Error: patchProperty/desc.set/wrapFn@http://localhost:3000/js/vendor/zone.js/dist/zone.js:769:27
Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://localhost:3000/js/vendor/zone.js/dist/zone.js:356:24
Zone</Zone</Zone.prototype.runTask@http://localhost:3000/js/vendor/zone.js/dist/zone.js:256:29
ZoneTask/this.invoke@http://localhost:3000/js/vendor/zone.js/dist/zone.js:423:29
Error loading http://localhost:3000/ng2-bootstrap/ng2-bootstrap as "ng2-bootstrap/ng2-bootstrap" from http://localhost:3000/js/app/alert.component.js