mck*_*kit 11 ng2-bootstrap angular
我无法导入ng2-bootstrap
layout.jade
html
head
title Angular 2 QuickStart
// 1. Load libraries
script(src="/node_modules/angular2/bundles/angular2-polyfills.js")
script(src="/node_modules/systemjs/dist/system.src.js")
//script(src="/node_modules/ng2-bootstrap/ng2-bootstrap.js")
script(src="/node_modules/rxjs/bundles/Rx.js")
script(src="/node_modules/angular2/bundles/angular2.dev.js")
// 2. Configure SystemJS
script.
System.config({
packages: {
app: {
//format: 'register',
//defaultExtension: 'js',
defaultJSExtensions: true
}
},
paths: {
'ng2-bootstrap/*': 'node_modules/ng2-bootstrap/*.js'
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
// 3. Display the application
body
my-app Loading...
Run Code Online (Sandbox Code Playgroud)
表达
app.use('/node_modules', express.static(__dirname + '/node_modules'));
Run Code Online (Sandbox Code Playgroud)
app.component.ts
//import "ng2-bootstrap/ng2-bootstrap";
import {Component} from 'angular2/core';
import {Alert} from 'ng2-bootstrap/ng2-bootstrap';
import {firstComponent} from './component/first.component';
@Component({
//directives: [Alert],
directives: [firstComponent,Alert],
selector: 'my-app',
template: `
<h1>My First Angular 2 App</h1>
<h2> helllo</h2>
<first></first>
<alert type="info">ng2-bootstrap hello!</alert>
`
})
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
错误控制台
GET http://localhost:3000/node_modules/ng2-bootstrap/components/accordion/accordion 404 (Not Found)
Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/ng2-
并且还有更多的错误与re:不能导入组件?
我自己也有同样的问题,发现此链接很有用:https://github.com/valor-software/ng2-bootstrap/issues/50#issuecomment-165448962
最相关代码的片段:
System.JS配置:
System.config({
packages: {
"app": {
"defaultExtension": "js"
},
"node_modules/ng2-bootstrap": {
"defaultExtension": "js"
}
},
paths: {
"ng2-bootstrap": "node_modules/ng2-bootstrap"
}
});
Run Code Online (Sandbox Code Playgroud)
然后你可以像这样导入它:
import { Progressbar } from "ng2-bootstrap";
@Component({
selector: "my-app",
directives: [
Progressbar
],
template: "<progressbar></progressbar>"
})
Run Code Online (Sandbox Code Playgroud)
希望这对你有所帮助,就像对我一样.
这对我有用.在systemjs.config文件下:
map: {
'ng2-bootstrap': 'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js',
'moment': 'node_modules/moment/moment.js'
}
Run Code Online (Sandbox Code Playgroud)
我们需要提及'时刻',因为ng2-bootstrap正在导入时刻.
在app.modules中,只需执行以下操作:
import {DatepickerModule} from 'ng2-bootstrap';
Run Code Online (Sandbox Code Playgroud)
还有以下内容:
@NgModule({
imports: [
....,
....,
DatepickerModule
],
declarations: [...],
providers: [...],
bootstrap: [AppComponent]
})
Run Code Online (Sandbox Code Playgroud)