Issue
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
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
Answered By - Aravind
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.