Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

131
Vistas
How can I recive a response data from an http request in Angular?

I want to read a response from a get http request, my server is in Javascript and the part of the where I send a response is:

app.get('/getReport',function(req,res) {
  try {
    const data=fs.readFileSync('./report.txt', 'utf8')
    res.end(data)
  }
  catch (err) {
    res.end("File not found")
  }
})

If if I use Postman I can see the content of the report file. I want to read this text on my Angular front-end so I create this function in my home.service.ts:

   public getReport(){
   return this.http.get<any>(this.url+'/getReport').subscribe(data => {
    this.value = data;})        
  }

It doesn't work. what can I do to read my content correctly?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Check your setup. You have to import some modules before get http requests:

@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],...
about 4 years ago · Juan Pablo Isaza Denunciar

0

In order to recive any response, you have to start a communication with your API/server subscribing to the 'getReport' method.

HOW CAN YOU DO THAT?

You have that method in your home.service.ts.

  1. Inject that service in the component where you want to load your report (i.e 'home-component'):
// NOTE: Fit all the paths to your specific system
...
import { HomeService } from '../services/home.service';
...

@Component({
  selector: 'app-home-component',
  templateUrl: './home-component.html',
  styleUrls: ['./home-component.scss'],
})
export class HomeComponent {

public report;

 constructor(
...
    private homeService: HomeService,
...

  ) {}
  1. Subscribe to the observable 'getReport' method of homeService, and get the desired data. For instance, change the constructor like this:
 constructor(
...
    private homeService: HomeService,
...

  ) {

       this.homeService.getReport
        .subscribe((_response) => {
           console.log(_response);
           this.report = _response;
           alert(this.report);
       });

}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda