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 { }