我对AngularJS很新。我正在使用Angular2制作一个Flickr公共提要应用程序,但我遇到了这个问题。Angular2 Flickr JSONP
我找不到让JSONP工作的方法。我该怎么做才能返回JSON对象?
这里的代码
flickr.service.ts
import { Injectable } from '@angular/core';
import { Jsonp, Http } from '@angular/http'; //use jsonp module to fetch the data from the api call
import 'rxjs/Rx'; // use rxjs as the observable
@Injectable()
export class FlickrService {
url: string;
apiKey: string = 'ffed2ef9dede27481c3195eea1be61eb';
constructor(private _jsonp: Jsonp) {
this.url = `https://api.flickr.com/services/feeds/photos_public.gne?&api_key=${this.apiKey}&per_page=12&format=json&nojsoncallback=1`;
}
getFeed() {
return this._jsonp.get(this.url)
.map(res => res.json());
}
searchTag(searchTerm: string) {
return this._jsonp.get(this.url+'&tag='+searchTerm)
.map(res => res.json());
}
}
flickr.component.ts
import { Component } from '@angular/core';
import { FlickrService } from '../services/flickr.service';
@Component({
moduleId: module.id,
selector: 'flickr',
templateUrl: './flickr.component.html'
})
export class FlickrComponent {
feedList: Array<Object>;
searchList: Array<Object>;
searchTerm: string;
constructor(private _flickrService: FlickrService) {
this._flickrService.getFeed().subscribe(res => {
console.log(res);
});
}
}
你可以添加ngmodule代码吗? – CharanRoot
你知道如何解决这个问题吗?我面临同样的问题。 –