2016-09-24 10 views
5

Gdy próbuję załadować moją aplikację kątową 2.0, pojawia się następujący błąd: (indeks): 21 Błąd: Błąd: nieoczekiwana wartość "[obiekt obiektu ]”przywożone przez moduł 'AppModule'Angular 2.0 Nieoczekiwana wartość "[object Object]" zaimportowana przez moduł "AppModule"

import { ModuleWithProviders } from '@angular/core'; 
import { Routes, RouterModule } from '@angular/router'; 
import { searchComponent }  from './search.Component'; 
import { landingComponent }  from './landing.Component'; 

export const routes: Routes = [ 
{ 
    path: '', 
    component: searchComponent 
}, 
{ 
    path: 'search', 
    component: searchComponent 
}]; 
export const routedComponents = [searchComponent, landingComponent]; 
export const routing: ModuleWithProviders = RouterModule.forRoot(routes); 

AppModule

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { landingComponent }    from './landing.Component'; 
import { searchComponent }    from './search.Component'; 
import { routes, routedComponents }  from './app.routing'; 
import { homeScript }     from './Services/homeScript'; 

@NgModule({ 
imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    routes 
], 
declarations: [ 
    landingComponent, 
    searchComponent, 
    routedComponents 
], 
providers: [ 
    homeScript 
], 
bootstrap: [landingComponent] 

}) 
export class AppModule { } 

script type do uruchomienia

///<reference path="./../typings/globals/core-js/index.d.ts"/> 
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 
import { AppModule } from './appModule'; 

platformBrowserDynamic().bootstrapModule(AppModule) 
    .then(success => console.log(`Bootstrap success`)) 
    .catch(error => console.log('GUY ' + error)); 

Jeśli usuniemy "trasy" z importu, strony docelowe zostaną załadowane, ale bez żadnego błędu wystąpi błąd związany z . Podejrzewam, że błąd w routingu, ponieważ jeśli usuniemy "trasy" w AppModule, strona docelowa ładuje się poprawnie. Próbowałem wielu zmian , ale nie byłem w stanie zidentyfikować przyczyny problemu. Każda pomoc będzie doceniona.

+0

Która wersja angular2 używasz? dlaczego potrzebujesz tego? 'export const routedComponents = [searchComponent, landingComponent];'. Jestem również nowy w angular2 i pracuję nad routingiem. Używam ostatecznej wersji angular2 i nie inicjuję powyższej instrukcji tak jak Ty. – Pradeepb

+0

Mam ten sam błąd, gdy próbuję załadować moduł z moduleWithProviders ... –

+0

Niestety zapomniałem wspomnieć o najbardziej podstawowych informacji: "@ kątowe/zwykłe": "2.0.1", –

Odpowiedz

6

Problem polega na ustawieniu routedComponents jako część swoich deklaracji. Ponieważ nie jest to dyrektywa, komponent lub rura, otrzymujesz ten wyjątek. Wyjąć routedComponents z modułu deklaracji tablicę i będzie rozwiązać problem.

+0

nie działa dla mnie – Demodave

+0

Nie działa również dla mnie. – Phill

1

Wystarczy usunąć "Trasy" z tablicy importu i dodać "routing" do:

imports: [ 
    BrowserModule, 
    FormsModule, 
    HttpModule, 
    routing 
] 
0
app.menurouting.ts 
export const menurouting:Routes=[{path:'',redirectTo:'menu',pathMatch:'full'}, 
      {path:'restarenttype',component:RestaurantTypeComponentComponent}, 
      {path:'table',component:TablelayoutComponent}, 
      {path:'blog',component:ViewmenuComponent}, 
     ]; 
     export const routes:ModuleWithProviders=RouterModule.forRoot(menurouting) 

    app.module.ts 

    import {routes} from './app.menurouting'; 

    @NgModule({ 
     declarations: [ 
     AppComponent, 
     LoginComponentComponent, 
     TablelayoutComponent, 
     ViewmenuComponent, 
     RestaurantTypeComponentComponent 
     ], 
     imports: [ 
     BrowserModule, 
     routes 
     ], 
     providers: [], 
     bootstrap: [AppComponent] 
    }) 
    export class AppModule { } 
+0

importuje klasy tras w tablicy –

Powiązane problemy