Error compiling project in Angular 5

0

I'm trying to get a JSON through POST with angular, but I get the following error.

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

I really do not know what it could be, it must be something simple, or some error due to some change in the version.

app.component.ts

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


//importar servicio

import { PostService } from './post.service';

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

export class AppComponent {


  title : string;

  nombre : string;
  email : string;


  //email = "[email protected]";

  //array
  hobbies : string[];

  mostradoHB : boolean;



constructor(private variablePostService:PostService) {

  this.variablePostService.obtenerPost().subscribe(post=> {

    console.log(post);

  });



  this.title = 'Aplicacion con angular';
  this.email = "[email protected]";
  this.nombre = 'Brian';

  this.hobbies = ['Correr','Leer', 'Ver series'];


  this.mostradoHB = true;

}//constructor

/*

toggleHobbies(){

  this.mostradoHB = !this.mostradoHB;

}


nuevoHobbie(dato){

  this.hobbies.push(dato.value);
  dato.value = '';
  //return false;

}

}

*/

}//clase

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http'; 

//aqui se cargan todos los componentes creados
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
    
asked by Brian Hernandez 16.04.2018 в 01:51
source

1 answer

2

Remove the semicolon ; that you have in the declaration of the annotation @Component of AppComponent that is causing the error:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [PostService]
}); <--- elimina este punto y coma

export class AppComponent
    
answered by 16.04.2018 / 03:11
source