Please add a @Pipe/@Directive/@Component annotation. Error

后端 未结 11 2219
滥情空心
滥情空心 2021-02-06 21:29

I am stuck in a situation here. I am getting an error like this.

 compiler.es5.js:1694 Uncaught Error: Unexpected value \'LoginComponent\' declared by the modul         


        
相关标签:
11条回答
  • 2021-02-06 22:09

    I faced the same error when I used another class instead of component down the component decorator.

    Component class must come just after the component decorator

      @Component({
     selector: 'app-smsgtrecon',
     templateUrl: './smsgtrecon.component.html',
     styleUrls: ['./smsgtrecon.component.css'],
     providers: [ChecklistDatabase]
     })
    
    
    // THIS CAUSE ISSUE MOVE THIS UP TO COMPONENT DECORATOR
    /**
    * Node for to-do item
    */
     export class TodoItemNode {
     children: TodoItemNode[];
     item: string;
    }
    
    
     export class SmsgtreconComponent implements OnInit {
    

    After moving TodoItemNode to the top of component decorator it worked

    Solution

    // THIS CAUSE ISSUE MOVE THIS UP TO COMPONENT DECORATOR
    /**
    * Node for to-do item
    */
     export class TodoItemNode {
     children: TodoItemNode[];
     item: string;
    }
    
    
    @Component({
     selector: 'app-smsgtrecon',
     templateUrl: './smsgtrecon.component.html',
     styleUrls: ['./smsgtrecon.component.css'],
     providers: [ChecklistDatabase]
     })
    
    
     export class SmsgtreconComponent implements OnInit {
    
    0 讨论(0)
  • 2021-02-06 22:10

    In my case, I accidentally added the package in the declaration but it should be in imports.

    0 讨论(0)
  • 2021-02-06 22:16

    If you are exporting another class in that module, make sure that it is not in between @Component and your ClassComponent. For example:

    @Component({ ... })
    
    export class ExampleClass{}
    
    export class ComponentClass{}  --> this will give this error.
    

    FIX:

    export class ExampleClass{}
    
    @Component ({ ... })
    
    export class ComponentClass{}
    
    0 讨论(0)
  • 2021-02-06 22:20

    You get this error when you wrongly add shared service to "declaration" in your appmodules instead of adding it to "provider".

    0 讨论(0)
  • 2021-02-06 22:21

    I had a component declared without the styleUrls property, like this:

    @Component({
        selector: 'app-server',
        templateUrl: './server.component.html'
    })
    

    instead of:

    @Component({
        selector: 'app-server',
        templateUrl: './server.component.html',
        styleUrls: ['./server.component.css']
    })
    

    Adding in the styleUrls property solved the issue.

    0 讨论(0)
  • 2021-02-06 22:24

    Not a solution to the concrete example above, but there may be many reasons why you get this error message. I got it when I accidentally added a shared module to the module declarations list and not to imports.

    In app.module.ts:

    import { SharedModule } from './modules/shared/shared.module';
    
    @NgModule({
      declarations: [
         // Should not have been added here...
      ],
      imports: [
         SharedModule
      ],
    
    0 讨论(0)
提交回复
热议问题