2016-08-16 15 views
8

Yeni Angular 2 RC5 yönlendiriciyi (yönlendirici sürümü RC1) kullanarak bir sorunla karşı karşıyayım.Köşeli 2 RC5: Router için sağlayıcı yok

İşte
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 {} 

benim boot.ts dosyasıdır:

İşte
EXCEPTION: Error in /templates/app.component.html:2:0 
ORIGINAL EXCEPTION: No provider for Router! 

gibi benim app.modules.ts görünür: Burada

Ben geliştirici konsolunda aldığım günlüğü olduğunu

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
import { AppModule } from './app.module'; 

platformBrowserDynamic().bootstrapModule(AppModule); 

My app.routes.ts dosya ...

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); 

... ve app.component.ts dosyası:

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; 
    } 
} 

Burada Eksik bir şey var mı? app.routes.ts dosyası içinde

+1

"useAsDefault" artık geçerli bir özellik değil. Ayrıca, yol özelliğindeki '/' öğesini kaldırır ve index.html dosyanıza değerini eklerim. –

+1

"Adı" Güzergahlarının da kaldırılması gerekiyor. – SudarP

cevap

9

:

Bu çalışması gerekir

export const routing: ModuleWithProviders = RouterModule.forRoot(routes); 

daha bu ithalat durumu

import { ModuleWithProviders } from '@angular/core'; 

ekleyin.

+0

Hey @EmmanuelScarabin Ekleme ModülüWithProviders benim için düzeltmedi. Router için 'Sağlayıcım yok!' App.component.html – SudarP

+1

@SudarP'ye etiketi eklediğimde hata, bileşenlerden herhangi birinde "yönlendirici-kullanım dışı" kullanıp kullanmadığınızı kontrol etmelisiniz. Bu konunun benim için ikinci sebebi buydu. –

+0

@EmmanuelScarabin, Çok teşekkürler bu düzeltildi. – SudarP

İlgili konular