我正在使用Angular 2快速入门并尝试添加第三方组件(具体为ng2-split-pane)。我用npm安装它,并根据它的plunkr示例我有以下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: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/material': 'npm:@angular/material/bundles/material.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
'autobahn': 'npm:@types/autobahn/index.d.ts',
'ng2-split-pane': 'npm:ng2-split-pane/lib/ng2-split-pane.js',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
以及以下app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MaterialModule } from '@angular/material';
import { BattleLogComponent } from './battlelog.component';
import { SplitPaneModule } from 'ng2-split-pane';
@NgModule({
imports: [ BrowserModule, MaterialModule, SplitPaneModule ],
declarations: [ AppComponent, BattleLogComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
但是我得到的错误是" app / app.module.ts(7,33):错误TS2307:找不到模块' ng2-split-pane'。&#34 ;
我可以加载其他东西(例如材料),我在这里缺少什么?
编辑:目录结构(空间省略了大多数node_modules):
.
├── app
│ ├── app.component.ts
│ ├── app.module.ts
│ ├── app.ng.css
│ ├── app.ng.html
│ ├── autobahn.service.ts
│ ├── battlelog.component.ts
│ ├── battlelog.ng.html
│ └── main.ts
├── favicon.ico
├── index.html
├── js
│ └── autobahn.min.js
├── LICENSE
├── node_modules
│ ├── mkdirp
│ ├── moment
│ ├── ms
│ ├── negotiator
│ ├── ng2-split-pane
│ ├── node-uuid
│ ├── nopt
├── package.json
├── styles.css
├── systemjs.config.extras.js
├── systemjs.config.js
├── tsconfig.json
└── tslint.json
答案 0 :(得分:0)
我能够通过使用以下方式明确说明ng2-split-pane的位置来使用angular-cli:
import { SplitPaneModule } from '../../node_modules/ng2-split-pane/src/ng2-split-pane';