我想你在做你的衣服时少了一些零件
http
请求获取数据,请尝试以下操作。请求应该与下面的内容类似,不能从图片中很好地计算出JSON。
请求
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
public getEarthquakes(): Observable<any>{
return this.http.get('http://earthquake.usgs.gov/
earthquakes/feed/v1.0/summary/all_hour.geojson').pipe(map(data => data));
}
//only on two lines for SO readability
组成部分
public earthQuakes = [];
getEarthqaukes(){
this.earthquakeService.getEarthquakes().subscribe(
(response) => {
console.log(response)
this.earthQuakes = response.features; // whichever bit you are looking for.
},
(error) => console.log(error)
);
}
HTML格式
<div *ngFor="let shake of earthQuakes">
<span>{{shake}}</span>
</div>
Documentation on using *ngFor
这并不像前面提到的那样完美,不能很好地看到完整的JSON,但这肯定足以填补空白。正如
the head rush
你应该看看这个
tutorial
确保你在学习的过程中了解自己在做什么。