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

153
Vistas
type void is not assignable to type any

I have a code in my component

export class AddNewCardComponent { 

    public concept = [];
    constructor( 
        private _router: Router,
        private _empDiscService: empDiscService) { 

        }

    ngOnInit(){
        this.concept = this._empDiscService.StoreMaster()
        .subscribe((data)=>{
            this.concept =  data;
        });
    }
}

its just i want to get var from services and put it in my store = [];

but it says

type void is not assignable to type any

here is my code in services

import {Injectable} from '@angular/core';
import { Httpprovider } from './httpprovider';

@Injectable()
export class empDiscService{

    public storedata = [];
    constructor(private _httpprovider: Httpprovider){

    }

    StoreMaster():Observable<any[]>{
        return this._httpprovider.httpReq('http://192.168.1.40:5000/getconcept','GET',null,null).map(res =>{<any[]>res.json()}
    };
}
about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

import { JobService } from './../services/job.service';
import { Component, OnInit } from '@angular/core';



@Component({
  selector: 'app-job-list',
  templateUrl: './job-list.component.html',
  styleUrls: ['./job-list.component.css']
})
export class JobListComponent implements OnInit {

 **jobs:any = [];**
erreur = '';
  constructor( private jobservice:JobService) { }

  ngOnInit() {
    this.jobservice.getJobs().subscribe(

      data => this.jobs = data,
      error => {console.log ('error')}

    );


  }

}
about 4 years ago · Santiago Trujillo Denunciar

0

You shall not subscribe() inside the service and return the object directly, which is not the intention of RxJs.

export class empDiscService{

    public storedata = [];
    constructor(private _httpprovider: Httpprovider){

    }
    StoreMaster():Observable<any[]>{
       return this._httpprovider.httpReq('http://192.168.1.40:5000/getmapmasterstore','GET',null,null).map(res =>{<any[]>res.json()}
    }

}

Your component should be

constructor( 
        private _router: Router,
        private _empDiscService: empDiscService) { 
          this.store = this._empDiscService.StoreMaster()
            .subscribe((data)=>{
                    this.storedata =  data;
        });
}

The actual mistake which you made is the service method was not returning anything

StoreMaster():Observable<any[]>{}

This will fix your problem

about 4 years ago · Santiago Trujillo Denunciar

0

StoreMaster() method does not return anything. You might need to change the service method to return the observable:

StoreMaster(){
return this._httpprovider.httpReq('http://192.168.1.40:5000/getmapmasterstore','' +
  '  GET',null,null).subscribe((data)=>{
  var brData = [];
  for (let i=0;i<data.length;i++){
    brData.push(data[i]);
  }
  return brData;
});
}

and ngOnInit

    ngOnInit(){
        this._empDiscService.StoreMaster()
            .subscribe(store => this.store = store);
    }
about 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