Я использую Angular5 для создания проекта.Я застрял в *ngFor
.У меня есть класс модели, как показано ниже:
export class FetchApi {
value: Array<String>;
api_status: string;
api_version: string;
data: Array<String>;
}
Мой component.ts получает данные от службы, которая вызывает API и извлекает данные.
Мой сервисный код:
public getUsers() {
console.log("heyyy"+this.fetchUrl);
return this.http.get <FetchApi[]> (this.fetchUrl); }
Мой код компонента:
ngOnInit() {
const scope = this;
this.userService.getUsers()
.subscribe( data => {
this.fetchApi = of(data);
console.log(this.fetchApi)
//this.fetchApi = data;
});
};
Мой JSON, который возвращает API, выглядит так:
{
"api_status": "200",
"api_version": "1.0",
"data": {
"featured": [{
"id": 1,
"vid": "",
"uid": ,
"title": "",
"description": ""
}]
}
}
Я хочу отобразить ответ на своей HTML-странице с помощью <tr *ngFor="let fetch-api of fetchApi ">
, однако получаю ошибку:
FetchApiComponent.html:22 ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngOnChanges (common.js:3121)
at checkAndUpdateDirectiveInline (core.js:8941)
at checkAndUpdateNodeInline (core.js:10209)
at checkAndUpdateNode (core.js:10171)
at debugCheckAndUpdateNode (core.js:10804)
at debugCheckDirectivesFn (core.js:10764)
at Object.eval [as updateDirectives] (FetchApiComponent.html:22)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:10756)
at checkAndUpdateView (core.js:10153)
at callViewAction (core.js:10394)
Пожалуйстадайте мне знать, что я делаю неправильно, поскольку я новичок в Angular5.Как я могу получить свой массив JSON на моей странице HTML.