尝试在角度2中使用路由器时出现以下错误: Error: Uncaught (in promise): TypeError: Cannot read property 'resolve' of undefined我无法弄清楚我的代码有什么问题。任何帮助都非常感谢。
我有以下文件
main.ts
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
app.component.ts
import { Component } from 'angular2/core';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from'angular2/router';
import { LoginComponent } from './login.component';
import { NotesComponent } from './notes.component';
@Component({
selector: 'my-app',
template: `
<h1> {{ title }} </h1>
<nav>
<a [routerLink]="['Login']">Login</a>
<a [routerLink]="['Notes']">Notes</a>
</nav>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES],
providers: [ROUTER_PROVIDERS]
})
@RouteConfig([
{
path: '/login',
name: 'Login',
component: LoginComponent,
useAsDefault: true
},
{
path: '/notes',
name: 'Notes',
component: NotesComponent
}
])
export class AppComponent{
title = 'Angular 2 test';
}
login.component.ts
import { Component } from 'angular2/core';
import { Router } from 'angular2/router';
@Component({
selector: 'login',
template: `<h1>Login Test</h1>`
})
export class LoginComponent {
}
notes.component.ts
import { Component } from 'angular2/core';
import { Router } from 'angular2/router';
@Component({
selector: 'notes',
template: `<h1>Notes Test</h1>`
})
export class NotesComponent {
}
答案 0 :(得分:0)
自beta.1以来,这是一个已知问题。使用未经编辑的脚本或更新到beta.16