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

238
Vistas
angular2/4 Observable subscription

Im trying to make a api call to my server database, but its not currenty working.

I have the following error:

enter image description here

    Type 'Subscription' is not assignable to type 'Observable<Comment[]>'.
  Property '_isScalar' is missing in type 'Subscription'.

What im i doing wrong and why?

import { Injectable } from '@angular/core';
import { Http, RequestOptions, URLSearchParams } from '@angular/http';
import {Observable} from 'rxjs/Observable';
import { Comment } from './models/comment'
import 'rxjs/add/operator/map';


@Injectable()
export class CoreService {

  constructor(private http: Http, private URLSearchParams : URLSearchParams) { }

  options = [];
  result = [];

  getUserByName(name: string): Observable<Comment[]> {

    let url = "http://localhost:8080/api";


    return this.http.get(url)
        .map(response => response.json())
        .subscribe(result => this.result = response);
  }

}

comment:

    export class Comment {
    constructor(
        public text:string
    ){}
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I think you are trying to subscribe to getUserByName() inside your component.

If that's the case you should remove subscribe from your service.

You can change it with the do() operator to "cache" your data.

return this.http.get(url)
        .map(response => response.json())
        .do(result => this.result = response);
over 4 years ago · Santiago Trujillo 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