简体   繁体   English

Angular 2.0 模块“AppModule”导入的意外值“[object Object]”

[英]Angular 2.0 Unexpected value '[object Object]' imported by the module 'AppModule'

When I try load my angular 2.0 application I get the following error: (index):21 Error: Error: Unexpected value '[object Object]' imported by the module 'AppModule'当我尝试加载我的 angular 2.0 应用程序时,我收到以下错误:(索引):21 错误:错误:模块“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 { }

Type script for booting用于启动的键入脚本

///<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 'routes' from the imports the landing pages loads but without any error.如果我从导入中删除“路由”,登录页面会加载但没有任何错误。 I suspect that the error in in the routing, because if I remove the 'routes' in the AppModule the landing page loads properly.我怀疑路由中的错误,因为如果我删除 AppModule 中的“路由”,登录页面会正确加载。 I have tried many changes but I have not been able to identify the cause of the problem.我尝试了许多更改,但我无法确定问题的原因。 Any help would be appreciated.任何帮助,将不胜感激。

The problem is you set routedComponents as part of your declarations. 问题是您将routedComponents设置为声明的一部分。 Since this is not a Directive, Component or Pipe you get this exception. 由于这不是指令,组件或管道,因此您会收到此异常。 Remove the routedComponents from the module declarations array and it will solve your issue. 从模块声明数组中删除routedComponents ,它将解决您的问题。

Just remove "routes" from import array and add "routing" to that: 只需从导入数组中删除“路由”并添加“路由”即可:

imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing
]
  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 { }

Be sure that modules are properly defined as @NgModule and watch out for the spelling of your classes to make sure they match up. 确保模块正确定义为@NgModule并注意类的拼写以确保它们匹配。

Please note that this is as of the Final release of Angular 2. 请注意,这是Angular 2的最终版本。

Also see this thread for additional discussion: Angular 2 Release "Unexpected value 'ElementRef' imported by the module" 另请参阅此主题以获得进一步的讨论: Angular 2发布“模块导入的意外值'ElementRef'”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 模块&#39;AppModule&#39;导入的意外值&#39;[object Object]&#39; - Unexpected value '[object Object]' imported by the module 'AppModule' Angular - 模块AppModule导入的意外值MatDialog - Angular - Unexpected value MatDialog imported by the module AppModule 模块&#39;AppModule&#39;导入了意外的值&#39;[object Object]&#39;。 请添加@NgModule批注 - Unexpected value '[object Object]' imported by the module 'AppModule'. Please add a @NgModule annotation 由angular2中的模块&#39;AppModule&#39;导入的意外值XXXX - Unexpected value XXXX imported by the module 'AppModule' in angular2 模块&#39;AppModule&#39;导入的意外值&#39;ImageUploadModule&#39; - Unexpected value 'ImageUploadModule' imported by the module 'AppModule' 模块&#39;AppModule&#39;导入的意外值&#39;MyCustomModule&#39; - Unexpected value 'MyCustomModule' imported by the module 'AppModule' 模块“AppModule”在语法错误处导入的意外值“未定义” - Unexpected value 'undefined' imported by the module 'AppModule' at syntaxError 模块“ AppModule”导入的异常值“ MdlModule” - Unexpected value 'MdlModule' imported by the module 'AppModule' 模块“ AppModule”导入的意外值“ PdfmakeModule” - Unexpected value 'PdfmakeModule' imported by the module 'AppModule' 模块“ AppModule”导入的异常值“ BootstrapModalModule” - Unexpected value 'BootstrapModalModule' imported by the module 'AppModule'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM