in angular2 app, have service send request url.
here service:
import {http} '@angular/http'; import {observable} 'rxjs/observable'; import 'rxjs/add/operator/map'; import {injectable} '@angular/core'; import {gallery} './gallery'; @injectable() export class instagramservice{ constructor(private _http:http){ } getgallery(username: string) : observable<gallery> { var result=this._http.get("https://www.instagram.com/"+username+"/media/").map(res => res.json()); console.log(result); return result; } } i have defined return type observable<gallery>, complains that:
a function declared type neither 'void' nor 'any' must return value what going wrong code?
if declare return type, why not return anything?
usually want in case.
getgallery(username: string) : observable<gallery> { return this._http.get("https://www.instagram.com/"+username+"/media/").map(res => res.json()); } var result doesn't expect anyway because _http.get(...) returns observable not value.
the caller of getgallery() can subscribe notified when value arrives.
instagramservice.getgallery.subscribe((result) => this.gallerydata = result); when value arrives (result) => this.gallerydata = result called , result assigned gallerydata of current component or service.
Comments
Post a Comment