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

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

提交回复
热议问题