【发布时间】:2019-10-15 09:01:10
【问题描述】:
我对 Angular 7 很陌生,我需要显示(在 HTML 文件中)来自本地存储的 JSON 文件的一些数据。
我已经设法将 json 文件中的数据放入一个数组中,我可以在 Chrome 控制台中显示它,但我无法在 Web 界面上显示它(通过 HTML 文件)
最好的方法是什么?
这是我的 json 文件:
{"latest_news": [{"title": "New Open Access Publication: EUROBENCH &
GET2EXCEL", "link":
"http://eurobench2020.eu/new-open-access-publication-eurobench-get2excel/"},
{"title": "Newsletter: EUROBENCH Begins to be a reality", "link":
"http://eurobench2020.eu/newsletter-eurobench-begins-to-be-a-reality/"},
{"title": "EUROBENCH at ERF 2019", "link":
"http://eurobench2020.eu/eurobench-at-erf-2019/"}, {"title":
"RobotUnion launches its second open call with \u20ac4 million public
funding for startups and SMEs", "link":
"http://eurobench2020.eu/robotunion-launches-its-second-open-call-with-e4-million-public-funding-for-startups-and-smes/"},
{"title": "Results of the 1st FSTP Open Call", "link":
"http://eurobench2020.eu/results-of-the-1st-fstp-open-call/"}]}
这是我的 news.component.ts :
import { Component, OnInit } from '@angular/core'; import {
HttpClient, HttpErrorResponse } from '@angular/common/http'; import
News_webscraper_data from './news_webscraper_data.json' import
{News_Item} from './news_item'
@Component({ selector: 'app-news', templateUrl:
'./news.component.html', styleUrls: ['./news.component.css'], })
export class NewsComponent implements OnInit { arrNews : News_Item
[] = News_webscraper_data constructor() { };
ngOnInit() {
console.log('Reading local json files');
console.log('arrNews:', this.arrNews) } }
我创建了一个 News_Item 类,如下所示:
export class News_Item {
title: string;
link : string;
}
【问题讨论】: