我需要使用一些HTML标记呈现JSON对象,
组件看起来像
import { Component, OnInit, } from '@angular/core';
import { BiblioService } from './biblio.service';
@Component({
selector: 'my-bibo',
templateUrl: 'biblio.component.html'
})
export class BiblioComponent implements OnInit {
constructor(private _BiblioService: BiblioService) {
this._BiblioService = _BiblioService
}
public index: any[] = [];
ngOnInit() {
this._BiblioService.getBiblio()
.subscribe(index => this.index = index);
}
}
模板看起来像这样:
<h1 data-animate="fadeIn"> {{index["hero-region"]["hero-headline"] </h1>
,输出看起来像
— Samuel Backett in <em>Proust</em>, 1930.
整个JSON文件看起来像
[{
"dc.rights": "xxxxxxxxxxxxx",
"hero-region": {
"hero-headline": "xxxxxxxxxxxxxx",
"hero-headline-sub": "— Samuel Backett in <em>Proust</em>, 1930."
}
}]
对此最好/最简单的解决方案是什么?