I have a service which queries for a json file hosted locally on my machine. The query to the service is called, but the return of the json data from the service query back to the component is consistently empty. However, using the developer tools in browser I can see that the json file with data is indeed being returned with a 200 ok.
Is there something fundamentally wrong with my subscriptions on the returning observable data? Any assistance is most appreciated.
@Injectable()
export class UserService {
constructor(
public http: Http,
) {}
search(query: string): Observable<UserInfo[]> {
return this.http.get('http://localhost/test.json')
.map(res => res.json());
}
}
valuechange(query) {
console.log("calling service from component");
this.inputFormControl.valueChanges
.debounceTime(4000)
.distinctUntilChanged()
.subscribe(query => this.userService.search(query)
.subscribe(data => {
{
this.data = data
console.log('this.users=' + this.data);
console.log('this.users.length=' + this.data.length);
}
}));
console.log("data on return from service is " + this.data[1]);
}