I have a spring boot web api running on the backend and i'm trying to cosume it from an angular 2 webApp, the HTTP response is like the following
我在后端运行了一个spring boot web api,我试图从一个有角度的2 webApp中获取它,HTTP响应如下所示
what I'm trying to do is convert the JSON object received as response to a defined Typescript class so I can use in my application
我想要做的是将收到的JSON对象转换为对定义的Typescript类的响应,以便我可以在我的应用程序中使用
1 个解决方案
#1
0
Angular 2 uses subscribe method. Try this:
Angular 2使用subscribe方法。尝试这个:
this.http.get('https://www.reddit.com/r/gifs/new/.json?limit=10').map(res => res.json()).subscribe(data => {
this.posts = data.data.children;
});
Used in Ionic 2 demo: https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/
用于Ionic 2演示:https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/
#1
0
Angular 2 uses subscribe method. Try this:
Angular 2使用subscribe方法。尝试这个:
this.http.get('https://www.reddit.com/r/gifs/new/.json?limit=10').map(res => res.json()).subscribe(data => {
this.posts = data.data.children;
});
Used in Ionic 2 demo: https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/
用于Ionic 2演示:https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/