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

后端 未结 11 2128
滥情空心
滥情空心 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:27

    In my case I mistakenly added this:

    @Component({
        selector: 'app-some-item',
        templateUrl: './some-item.component.html',
        styleUrls: ['./some-item.component.scss'],
        providers: [ConfirmationService]
    })
    
    declare var configuration: any;
    

    while the correct form is:

    declare var configuration: any;
    
    @Component({
        selector: 'app-some-item',
        templateUrl: './some-item.component.html',
        styleUrls: ['./some-item.component.scss'],
        providers: [ConfirmationService]
    })    
    
    0 讨论(0)
  • 2021-02-06 22:28

    The Above error occurs if any wrong import done. For example sometimes Service files may be added in TestBed.configureTestingModule. And also while importing Material component for example import from

    import {MatDialogModule} from '@angular/material/dialog'
    

    not from

    import {MatDialogModule} from '@angular/material'
    
    0 讨论(0)
  • 2021-02-06 22:28

    I was trying to use BrowserModule in a shared module (import and export). That was not allowed so instead I had to use the CommonModule instead and it worked.

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

    You have a typo in the import in your LoginComponent's file

    import { Component } from '@angular/Core';

    It's lowercase c, not uppercase

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

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

    Another solution is below way and It was my fault that when happened I put HomeService in declaration section in app.module.ts whereas I should put HomeService in Providers section that as you see below HomeService in declaration:[] is not in a correct place and HomeService is in Providers :[] section in a correct place that should be.

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule  } from '@angular/core';
    import { HttpModule } from '@angular/http';
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { HomeComponent } from './components/home/home.component'; 
    import { HomeService } from './components/home/home.service';
    
    
    @NgModule({
      declarations: [
        AppComponent,
        HomeComponent,  
        HomeService // You will get error here
      ],
      imports: [
        BrowserModule,
        BrowserAnimationsModule,
        AppRoutingModule
      ],
      providers: [
        HomeService // Right place to set HomeService
      ],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    hope this help you.

    0 讨论(0)
提交回复
热议问题