导入第三方库

时间:2016-12-12 17:03:38

标签: angular systemjs

我正在尝试在angular2应用程序中使用angular2-datatable 但在AppModule中输入导入后尝试运行应用程序时出现以下错误

Error: (SystemJS) Unexpected token <

这是AppModule

 import { NgModule } from '@angular/core';
 import { BrowserModule } from '@angular/platform-browser';
 import { HttpModule } from '@angular/http';
 import { AppComponent } from './app.component'
 import { FormsModule } from '@angular/forms';
 import { RouterModule } from '@angular/router';
 import { APP_BASE_HREF } from '@angular/common';
 import { SelectModule } from 'angular2-select';
 import { AppRoutes } from './app.routes';
 import { DataTableModule } from "angular2-datatable";


@NgModule({
declarations: [
AppComponent
],
providers: [{ provide: APP_BASE_HREF, useValue: '/' }],
imports: [
BrowserModule,
HttpModule,
FormsModule,
SelectModule,
DataTableModule,
RouterModule.forRoot(AppRoutes)],
bootstrap: [AppComponent]
})
export class AppModule { }

这是我的systemjs.config

(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',
        // other libraries
        'rxjs': 'npm:rxjs',
        'angular2-select': 'node_modules/angular2-select',
        'angular2-datatable': 'node_modules/angular2-datatable'
    },
    // 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'
        },
        'angular2-select': {
            main: 'index.js',
            defaultExtension: 'js'
        },
        'angular2-datatable': {
            main: 'index.js',
            defaultExtension: 'js'
        }
    }
});
})(this);

我以同样的方式导入了其他库,所以我不确定我缺少什么。 有什么想法吗?

1 个答案:

答案 0 :(得分:1)

看起来您需要确保系统js中也引用了lodash。尝试添加这个......

'angular2-select': 'node_modules/angular2-select',
'angular2-datatable': 'node_modules/angular2-datatable',
'lodash': 'npm:lodash/lodash'           <----------------HERE

'lodash': 'node_modules/lodash'

这是我的plunker正确导入它 https://plnkr.co/edit/Yv7gO1eYYNIIOsoDdQrt?p=preview