0

I want to see the result returned from the service in the same subscribe method or in the ngOninit method(commented one) but neither of the place it showing the result even it is fetching the result from the service..

ngOnInit() {
    this.cityAreaService.getCities().subscribe(data => {
        this.cities = data;
        //console.log(this.cities);
    });
    //console.log(this.cities) 
}

Service

getCities() {
    return this.http.get(globalVar.serviceUrl + 'Cities').map((res: Response) => res.json());
}
Rakesh Chand
  • 3,105
  • 1
  • 20
  • 41
Nitin Shekhar
  • 175
  • 2
  • 15

1 Answers1

-2

You could try to read response in other blocks of subscribe

this.cityAreaService.getCities().subscribe(
  response => {
    this.cities = response;
  },
  error => {
    // maybe error
  },
  () => {
    // anything else?
  }
);
netic
  • 2,854
  • 6
  • 28
  • 25