Angular 2.0 Unexpected value "Object object" imported by the module "AppModule",

When I try to download my angular 2.0 application, I get the following error: (index): 21 Error: Error: Unexpected value of "Object object" imported by the "AppModule" module

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

Enter script to load

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

If I remove the “routes” from the import, the landing pages are loaded, but without any error. I suspect a routing error because if I delete the “routes” in the AppModule the landing page loads properly. I tried a lot but I could not determine the cause of the problem. Any help would be appreciated.

+5
source share
4 answers

The problem is that you are installing routedComponents as part of your ads. Since this is not a Directive, Component or Pipe, you receive this exception. Remove the routedComponents from the ad array and it will solve your problem.

+7
source

Just remove the “routes” from the import array and add “routing” to this:

 imports: [ BrowserModule, FormsModule, HttpModule, routing ] 
+1
source
  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
source

Make sure the modules are correctly defined as @NgModule and watch your classes write to make sure they match.

Please note that this applies to the final version of Angular 2.

Also see this topic for further discussion: Angular 2 Release "Unexpected ElementRef 'value imported by module"

-2
source

All Articles