我正面臨使用新的Angular 2 RC5路由器(路由器版本爲RC1)的問題。Angular 2 RC5:沒有路由器的供應商
這裏是日誌我從開發者控制檯獲得:
EXCEPTION: Error in /templates/app.component.html:2:0
ORIGINAL EXCEPTION: No provider for Router!
這裏是我的app.modules.ts是什麼樣子:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './components/app.component';
import { routing } from './app.routes';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, RouterModule, FormsModule, HttpModule, routing],
bootstrap: [AppComponent],
})
export class AppModule {}
這裏是我的boot.ts文件:
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
我app.routes.ts文件...
import { Routes, RouterModule } from '@angular/router';
// Components
import { HomeComponent } from './components/home.component';
const routes: Routes = [
// Root
{ path: '/', name: 'Home', component: HomeComponent, useAsDefault: true},
];
// - Updated Export
export const routing = RouterModule.forRoot(routes);
...和我app.component.ts文件:
import { Component, ViewContainerRef } from '@angular/core';
@Component({
selector: 'app',
templateUrl: '/templates/app.component.html'
})
export class AppComponent {
viewContainerRef: any;
public constructor(viewContainerRef:ViewContainerRef) {
// You need this small hack in order to catch application root view container ref
this.viewContainerRef = viewContainerRef;
}
}
有我丟失的東西嗎?
「useAsDefault」不再是有效的屬性。我還會刪除path屬性中的'/',並將 添加到index.html文件中。 –
路由「名稱」也需要刪除。 – SudarP