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

398
Vistas
Impossible to use res.name because of subscribe (ANGULAR)

Currently I am following a tutorial on Youtube in which it uses authentication with Angular and I can't continue at this point :

Code from Youtube tutorial

His code does not work on my side because of subscribe() which gives me the message:

@deprecated — Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments

I'm forced to use next, error and complete and and despite everything, the res.name is not displayed.

ngOnInit(): void {
  this.http.get(
    'http://localhost:8080/api/user',
    {withCredentials: true}
    ).subscribe({
    complete: () => { (res: any) => this.visiteur = `${res.nom}`  },
    error: () => { (err: any) => console.log(err)  },
    next: () => { (res: any) => this.visiteur = `${res.nom}`  }
    });
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The current way of subscribing is using more of rxjs operators, The tutorial you are following seems a little outdated. I recommend you follow angular's Tour of heroes tutorial instead. It is always up-to-date.

This should get you going:

this.http
    .get('http://localhost:8080/api/user')
    .pipe(
        catchError(err => {
            console.log(err);
        })
    )
    .subscribe(data => {
        this.visiteur = `${data.nom}`;
    });

Also I would recommend you implement an angular http interceptor to pass in http required attributes/headers (in your case withCredentials). But this is optional for the scope of this question.

And finally, don't forget to avoid the memory-leak trap with subscriptions.

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