Unexpected value 'AnyComponent' declared by the module 'AppModule'

Herlon Aguiar

I'm using Angular2 and I got this problem when tryng to use two classes in the same Typescript file.

At compile time doesn't give me any error but when I try to execute the page the console.log is giving this error:

Error: BaseException@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:5116:27
    CompileMetadataResolver</CompileMetadataResolver.prototype.getNgModuleMetadata/<@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:13274:35
    CompileMetadataResolver</CompileMetadataResolver.prototype.getNgModuleMetadata@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:13261:21
    RuntimeCompiler</RuntimeCompiler.prototype._compileComponents@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:15845:28
    RuntimeCompiler</RuntimeCompiler.prototype._compileModuleAndComponents@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:15769:36
    RuntimeCompiler</RuntimeCompiler.prototype.compileModuleAsync@http://www.my.app/panel-module/node_modules/@angular/compiler//bundles/compiler.umd.js:15746:20
    PlatformRef_</PlatformRef_.prototype._bootstrapModuleWithZone@http://www.my.app/panel-module/node_modules/@angular/core//bundles/core.umd.js:9991:20
    PlatformRef_</PlatformRef_.prototype.bootstrapModule@http://www.my.app/panel-module/node_modules/@angular/core//bundles/core.umd.js:9984:20
    @http://www.my.app/panel-module/app/main.js:4:1
    @http://www.my.app/panel-module/app/main.js:1:31
    @http://www.my.app/panel-module/app/main.js:1:2
    Zone</ZoneDelegate</ZoneDelegate.prototype.invoke@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:332:20
    Zone</Zone</Zone.prototype.run@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:225:25
    scheduleResolveOrReject/<@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:586:53
    Zone</ZoneDelegate</ZoneDelegate.prototype.invokeTask@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:365:24
    Zone</Zone</Zone.prototype.runTask@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:265:29
    drainMicroTaskQueue@http://www.my.app/panel-module/node_modules/zone.js/dist/zone.js:491:26
    F/</g@http://www.my.app/panel-module/node_modules/core-js/client/shim.min.js:8:10016
    F/<@http://www.my.app/panel-module/node_modules/core-js/client/shim.min.js:8:10138
    a.exports/k@http://www.my.app/panel-module/node_modules/core-js/client/shim.min.js:8:14293

    Evaluating http://www.my.app/panel-module/app/main.js
    Error loading http://www.my.app/panel-module/app/main.js

Below is my component typescript file.

// MyComponent.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: '/path/to/view',
})

export class MyObject {
  id: number;
}


export class MyComponent {
   obj: MyObject;

   // unecessary code
}
slaesh

You have to change the order of your classes, then there is no problem to have multiple classes in the same file. Cause in your case that decorator @Component is now being used for your class MyObject instead of MyComponent !

The decorator @Component needs to be directly in front of your Component definition!!

import { Component, OnInit } from '@angular/core';


export class MyObject1 {
  id: number;
}

@Component({
  selector: 'my-app',
  templateUrl: '/path/to/view',
})
export class MyComponent {
   obj: MyObject;

   // unecessary code
}

export class MyObject2 {
  id: number;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Uncaught Error: Unexpected module 'FormsModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation

From Java

Error: Unexpected value 'undefined' imported by the module

From Java

Uncaught Error: Unexpected directive 'MatFormField' imported by the module 'AppModule'. Please add a @NgModule annotation

From Dev

List declared directives/controllers in AngularJS module

From Dev

Printing declared char value in C

From Dev

function is undefined if no module is declared in Angular

From Dev

React import a module with a declared namespace

From Dev

Member is declared in another module and needs to be imported

From Dev

Unexpected value of __callee__ when including a module – is this a Ruby bug?

From Dev

Get list of all declared module imports (SystemJS)

From Dev

how to update the value of a declared variable

From Dev

Default value of enum declared in class

From Dev

default export is not declared in imported module

From Dev

Error: Unexpected value 'undefined' exported by the module 'DynamicFormModule'

From Dev

Angular2: Error: unexpected value 'AppComponent' declared by the module 'AppModule'

From Dev

React import a module with a declared namespace

From Dev

Printing declared char value in C

From Dev

how to update the value of a declared variable

From Dev

Unexpected value 'Component' declared by the module 'AppModule'

From Dev

Error: (SystemJS) Unexpected value 'undefined' imported by the module 'AppModule'

From Dev

Unexpected value XXXX imported by the module 'AppModule' in angular2

From Dev

Error: (SystemJS) Unexpected value 'CommonService' declared by the module 'AppModule'

From Dev

Unexpected value 'SohoComponentsModule' imported by the module 'DynamicTestModule'

From Dev

Angular 2, when to reference module in appmodule and when to reference in component?

From Dev

Uncaught Error: Unexpected value 'PropDecoratorFactory' imported by the module 'AppModule'. Please add a @NgModule annotation

From Dev

Uncaught Error: Unexpected value 'SharedModule' imported by the module 'AppModule'. Please add a @NgModule annotation

From Dev

Unexpected value imported by the module please add a @ngmodule annotation

From Dev

declared value to be used in formula

From Dev

Use initial value after declared

Related Related

  1. 1

    Uncaught Error: Unexpected module 'FormsModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation

  2. 2

    Error: Unexpected value 'undefined' imported by the module

  3. 3

    Uncaught Error: Unexpected directive 'MatFormField' imported by the module 'AppModule'. Please add a @NgModule annotation

  4. 4

    List declared directives/controllers in AngularJS module

  5. 5

    Printing declared char value in C

  6. 6

    function is undefined if no module is declared in Angular

  7. 7

    React import a module with a declared namespace

  8. 8

    Member is declared in another module and needs to be imported

  9. 9

    Unexpected value of __callee__ when including a module – is this a Ruby bug?

  10. 10

    Get list of all declared module imports (SystemJS)

  11. 11

    how to update the value of a declared variable

  12. 12

    Default value of enum declared in class

  13. 13

    default export is not declared in imported module

  14. 14

    Error: Unexpected value 'undefined' exported by the module 'DynamicFormModule'

  15. 15

    Angular2: Error: unexpected value 'AppComponent' declared by the module 'AppModule'

  16. 16

    React import a module with a declared namespace

  17. 17

    Printing declared char value in C

  18. 18

    how to update the value of a declared variable

  19. 19

    Unexpected value 'Component' declared by the module 'AppModule'

  20. 20

    Error: (SystemJS) Unexpected value 'undefined' imported by the module 'AppModule'

  21. 21

    Unexpected value XXXX imported by the module 'AppModule' in angular2

  22. 22

    Error: (SystemJS) Unexpected value 'CommonService' declared by the module 'AppModule'

  23. 23

    Unexpected value 'SohoComponentsModule' imported by the module 'DynamicTestModule'

  24. 24

    Angular 2, when to reference module in appmodule and when to reference in component?

  25. 25

    Uncaught Error: Unexpected value 'PropDecoratorFactory' imported by the module 'AppModule'. Please add a @NgModule annotation

  26. 26

    Uncaught Error: Unexpected value 'SharedModule' imported by the module 'AppModule'. Please add a @NgModule annotation

  27. 27

    Unexpected value imported by the module please add a @ngmodule annotation

  28. 28

    declared value to be used in formula

  29. 29

    Use initial value after declared

HotTag

Archive