Angular 2路由器错误:未捕获(在承诺中):TypeError:无法读取未定义

时间:2016-04-27 16:51:41

标签: angular angular2-routing

尝试在角度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 {

}

1 个答案:

答案 0 :(得分:0)

自beta.1以来,这是一个已知问题。使用未经编辑的脚本或更新到beta.16