当我运行以下代码时,我在浏览器控制台中看到此错误:
Uncaught SyntaxError: Unexpected token <
Uncaught SyntaxError: Unexpected token <
Evaluating http://localhost:3002/angular2/router
Error loading http://localhost:3002/public/boot.jsrun @ angular2
没有其他明显的错误消息。
当我从以下组件中删除与路由器相关的代码时,错误就会消失。
import {Component} from 'angular2/core';
import {GeoSelector} from './geo-selector.component';
import {RouterOutlet, RouteConfig} from 'angular2/router';
@Component({
selector: 'va-helps-app',
templateUrl: `
<header>
<div class="masthead">
<h1>{{siteTitle }}</h1>
<h2> {{siteSubtitle }}</h2>
</div>
<nav class="main-navbar">
<ul>
<li><a href="#"> Search </a></li>
<li><a href="#"> About </a></li>
<li><a href="#"> Submit </a></li>
<li><a href="#"> Contact </a></li>
</ul>
</nav>
</header>
<router-outlet></router-outlet>
`,
directives: [GeoSelector, RouterOutlet]
})
@RouteConfig([
{ path: '/home', as: 'home', component: GeoSelector }
])
export class AppComponent {
public siteTitle = "Virginia Helps"
public siteSubtitle = "This is what the site is for";
}
有人能指出我正确的方向来解决这个问题吗?
答案 0 :(得分:3)
也许您忘了将router.dev.js
文件包含在Angular2应用程序的index.html
文件中:
<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>
否则您显示的代码似乎是正确的。
希望它可以帮到你, 亨利