我正在使用角度2 beta 17,但发生错误。当我尝试路由到另一个组件时。请指导我。我将非常感谢你。
import {Component} from 'angular2/core';
import {Http, HTTP_PROVIDERS} from 'angular2/http';
import {MvcComponent} from "./components/mvc.component";
import {Location} from 'angular2/platform/common';
import {Router, RouteDefinition, RouteConfig, ROUTER_DIRECTIVES} from "angular2/router";
@Component({
selector: 'my-app',
templateUrl: './appScripts/layout/sidebar.html',
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{
path: '/index',
name: 'Index',
component: MvcComponent,
useAsDefault: true
}
])
export class AppComponent {
Profileimageurl: string = './images/flat-avatar.png';
public routes: RouteDefinition[] = null;
constructor(private router: Router,
private location: Location) {
}
getLinkStyle(route: RouteDefinition) {
return this.location.path().indexOf(route.path) > -1;
}
}
答案 0 :(得分:1)
我认为您忘记在主HTML文件中包含以下文件:
<script src="node_modules/angular2/bundles/router.dev.js"></script>