I keep getting this error Uncaught SyntaxError: Unexpected token < whenever I try to start an angular2 application. This is just a modification based on the routing of the "tutorial" of the angular2 website.
Typically, such errors speak for themselves, where I wrote the code fragment incorrectly. But the Chrome console tells me that the error is happening inside the angular2 js file.
Reading and testing responses from Chrome Uncaught Syntax Error: Unexpected Token ILLEGAL and warning C4819: How to find the character that has to be saved in unicode? did not help. Assuming the error should be somewhere in my boot.ts or app.component.ts.
boot.ts
import {bootstrap} from 'angular2/platform/browser'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component'; import {HallService} from './hall/hall.service'; bootstrap(AppComponent,[ ROUTER_PROVIDERS, HallService ]);
app.component.ts
import {Component} from 'angular2/core'; import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router'; import {HallCenterComponent} from './hall/hall-center.component'; @Component({ selector: 'my-app', template: ` <h1 class="title">Component Router</h1> <a [routerLink]="['HallCenter']">Hallen</a> <a>Heroes</a> <router-outlet></router-outlet> `, directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ { path: '/hall/...', name: 'HallCenter', component: HallCenterComponent, useAsDefault: true } ]) export class AppComponent { }
index.html
<html> <head> <base href="/"> <title>Factory project</title> <link rel="stylesheet" href="styles.css"> <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/rxjs/bundles/Rx.js"></script> <script src="node_modules/angular2/bundles/angular2.dev.js"></script> <script src="node_modules/angular2/bundles/router.dev.js"></script> <script> System.config({ packages: { app: { format: 'register', defaultExtension: 'js' } } }); System.import('app/boot') .then(null, console.error.bind(console)); </script> </head> <body> <my-app>loading...</my-app> </body> </html>
Hall-center.component.ts
import {Component} from 'angular2/core'; import {RouteConfig, RouterOutlet} from 'angular2/router'; import {HallListComponent} from './hall-list.component'; import {HallDetailComponent} from './hall-detail.component'; import {HallService} from './hall.service'; @Component({ template: ` <h2>HALL CENTER</h2> <router-outlet></router-outlet> `, directives: [RouterOutlet], providers: [HallService] }) @RouteConfig([ {path:'/', name: 'HallCenter', component: HallListComponent, useAsDefault: true}, {path:'/:id', name: 'HallDetail', component: HallDetailComponent}, {path:'/list/:id', name: 'HallList', component: HallListComponent} ]) export class HallCenterComponent { }