'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()}
};
}
Solution 1:[1]
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')}
);
}
}
Solution 2:[2]
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user2907200 |
| Solution 2 | Tomislav Stankovic |
