Angular 2 router Error: Uncaught (in promise): Typ

2019-07-15 05:39发布

问题:

I am getting the following error when trying to use the router in angular 2: Error: Uncaught (in promise): TypeError: Cannot read property 'resolve' of undefined and I can't figure out what's wrong with my code. Any help is really appreciated.

I have the following files

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:

That's a known issue since beta.1.Either use unminified scripts or update to beta.16