SyntaxError:意外的标记<at eval =“”(<anonymous =“”>)Angular 2

时间:2017-01-11 05:34:24

标签: jquery asp.net-mvc angular asp.net-core angular-datatables

我通过以下链接https://www.npmjs.com/package/angular2-datatable

使用数据表

我已按照此链接的每一步操作但是我收到错误,如下所示

SyntaxError: Unexpected token <
        at eval (<anonymous>)
        at Object.eval (http://localhost:28739/app/app.module.js:25:28)
        at eval (http://localhost:28739/app/app.module.js:66:4)
        at eval (http://localhost:28739/app/app.module.js:67:3)
    Evaluating http://localhost:28739/angular2-datatable
    Evaluating http://localhost:28739/app/app.module.js
    Evaluating http://localhost:28739/app/main.js
    Error loading http://localhost:28739/app/main.js
(anonymous) @ localhost/:27

这是我的module.ts

我因为导入案例而收到错误我认为是这样。但是无法弄明白。

    import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { DataTableModule } from "angular2-datatable";
import { Routes,RouterModule} from '@angular/router';
import { HttpModule, JsonpModule } from '@angular/http';
import { ModuleWithProviders } from '@angular/core';
import { AppComponent} from "./app.component";
import { EqualValidator } from "./Validation/equal.validator.directive";
import { LoginComponent } from "./Components/login.Component";
import { HomeComponent } from "./Components/home.component";
import { DashBoardComponent } from "./Components/dashBoard.Component";
import { FooterComponent } from "./Components/footer.Component";
import { NavComponent } from "./Components/nav.Component";
import { DashBoardItemComponent } from "./Components/dashBoard.Item.Component";
import { MarketComponent } from "./Components/market.Component";



const appRoutes: Routes = [
    { path: '', redirectTo: 'Home/Index', pathMatch: 'full' },
    { path: 'DashBoard/Index', children: [
                                { path: '', component: DashBoardItemComponent},
                                { path: '', component: DashBoardComponent, outlet: 'dashboard' }
                                ]},
    { path: 'Account/Login', children: [
                                {path: '', component: NavComponent, outlet: 'navbar'},
                                {path: '', component: LoginComponent},
                                {path: '', component: FooterComponent, outlet: 'footer'}
                                ]},
    { path: 'Home/Index', children: [
                            {path: '', component: NavComponent, outlet: 'navbar'},
                            {path: '', component: HomeComponent},
                            {path: '', component: FooterComponent, outlet: 'footer'}
                            ]},
    {
        path: 'DashBoard/MarketList',
        children: [
            { path: '', component: DashBoardComponent, outlet: 'dashboard' },
            { path: '', component: MarketComponent }
        ]
    }
];



export const routing = RouterModule.forRoot(appRoutes);

@NgModule({
    imports: [BrowserModule, DataTableModule,FormsModule, HttpModule,routing],
    declarations: [AppComponent, LoginComponent, HomeComponent, DashBoardComponent, EqualValidator,FooterComponent,NavComponent,DashBoardItemComponent,MarketComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

我已安装数据表并包含在导入中。我在做错的地方。

我谷歌发现由于导入问题可能会发生此错误。但我不知道。

请有人告诉我如何解决此问题

1 个答案:

答案 0 :(得分:0)

错误必须是因为所需的js文件未包含在systemjs.config.js文件中。您必须在systemjs.config.js中包含必需的js文件以实现angular2-datatable。 systemjs.config文件中需要的一小段代码如下所示:

map: {
'angular2-datatable': 'npm:angular2-datatable,
}

packages: {
          'angular2-datatable': {
            main: 'index.js',
            defaultExtension: 'js'
          }
}