2016-12-26 10 views
0

イムでAngular2のルータをしようと、 は、私はそのように見えるapp.routing.tsファイル、作成:予期しない値XXXX「AppModule」angular2

import {NgModule} from '@angular/core'; 
import {Routes, RouterModule} from '@angular/router'; 

import { NewNoteComponent } from './components/new-note.component'; 
import { NoteListComponent } from './components/note-list.component'; 


const routes: Routes =[ 
    {path: '', pathMatch: '', redirectTo: 'note-list'}, 
    {path: 'note-list', component: NoteListComponent}, 
    {path: 'new-note', component: NewNoteComponent} 
]; 

NgModule({ 
    imports: [RouterModule.forRoot(routes)], 
    exports: [RouterModule] 
}) 

export class AppRoutingModule{} 

export const routingComponents = [NewNoteComponent, NoteListComponent]; 

をし、そのように私のapp.module.tsを設定します。

import { NgModule }  from '@angular/core'; 
import {HttpModule} from '@angular/http'; 
import { BrowserModule } from '@angular/platform-browser'; 
import {FormsModule} from '@angular/forms'; 
import { AppComponent } from './app.component'; 


import {AppRoutingModule, routingComponents} from './app.routing'; 
import { SearchComponent} from './components/search.component'; 


@NgModule({ 
    imports: [ BrowserModule , FormsModule, AppRoutingModule, HttpModule], 
    declarations: [ AppComponent, SearchComponent, NoteListComponent], 
    bootstrap: [ AppComponent ] 
}) 




export class AppModule { } 

私の問題は、私はこの事を実行しようとすると、それは私にそのUnexpected value 'AppRoutingModule' imported by the module 'AppModule'

を言って thatsのを奇妙なエラーをスローだということです

これは本当に簡単だと思いますが、私がやったばかげたミスを心配しています。

答えて

1

NgModuleの前にAppRoutingModuleの中に@がありません。

import {NgModule} from '@angular/core'; 
import {Routes, RouterModule} from '@angular/router'; 

import { NewNoteComponent } from './components/new-note.component'; 
import { NoteListComponent } from './components/note-list.component'; 


const routes: Routes =[ 
    {path: '', pathMatch: '', redirectTo: 'note-list'}, 
    {path: 'note-list', component: NoteListComponent}, 
    {path: 'new-note', component: NewNoteComponent} 
]; 

@NgModule({ 
    imports: [RouterModule.forRoot(routes)], 
    exports: [RouterModule] 
}) 

export class AppRoutingModule{} 

export const routingComponents = [NewNoteComponent, NoteListComponent]; 

そして、あなたはあなたのAppModuledeclarationsroutingComponentsを使用する必要があります。

@NgModule({ 
    imports: [ BrowserModule , FormsModule, AppRoutingModule, HttpModule], 
    declarations: [ AppComponent, SearchComponent, routingComponents], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 
+1

私のああ..あなたに感謝!私はあなたのそれらの鷹の目が必要でした;)ありがとう! – thormayer

関連する問題