Angular 2 RC3“没有RouterOutletMap的提供者!”错误

时间:2016-06-27 12:04:38

标签: angular

我有一个Angular 2应用程序,我刚刚升级为使用"2.0.0-rc.3"

我正在使用"@angular/router": "3.0.0-alpha.7"的新路由器,

现在,当我尝试在浏览器中加载应用时,我看到以下异常......

VM17108:77 ORIGINAL EXCEPTION: No provider for RouterOutletMap!

我的app.component.ts看起来像......

import {Component} from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';
import 'rxjs/Rx';   // Load all features
import {ROUTER_DIRECTIVES, provideRouter, RouterConfig } from '@angular/router';

import { TilesService } from '../app/shared/services/tiles.service'
import { LocationService } from '../app/shared/services/location.service'

@Component({
    selector: 'tc-app',
    template: '<router-outlet></router-outlet>',

    directives: [ROUTER_DIRECTIVES],
    providers: [HTTP_PROVIDERS,
                TilesService,
                LocationService
               ]
})

export class AppComponent {  pageTitle: string = 'TileCase'; }

我的app.routes.ts看起来像这样......

import { provideRouter, RouterConfig } from '@angular/router';

import { TilesComponent } from '../app/tiles/tiles.component';
import { ProfileComponent } from '../app/profile/profile.component';

export const routes: RouterConfig = [
  { path: '', component: TilesComponent }
  , { path: 'profile/:id', component: ProfileComponent }
];

export const APP_ROUTER_PROVIDERS = [
  provideRouter(routes)
];

我的main.ts看起来像这样......

import {bootstrap}    from '@angular/platform-browser-dynamic';
import {AppComponent} from './app.component';
import { APP_ROUTER_PROVIDERS } from './app.routes';

bootstrap(AppComponent, [
    APP_ROUTER_PROVIDERS
])
    .catch(err => console.error(err));

使用RC2时,这一切都很好。我无法弄清楚我需要做些什么来重新开始这项工作。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我已经把这个想出来了。这实际上是一个Webpack错误。 Webpack没有正确设置,因此没有正确构建js导致错误。 感谢大家的帮助。