How can I extract and display the ID and title of the Hero object below? The structure of the Hero interface is based on a Firebase JSON response.
hero.component.ts
import {Component, Input} from 'angular2/core';
import {Hero} from '../model/hero';
@Component({
selector: 'hero-component',
template:``
{{hero | json }} - this code works fine. It shows the Firebase JSON response below.
<br>
{{ Object.keys(hero)[0] }} - this part does not work as expected.
<br>
{{ hero[Object.keys(hero)[0]].title }} - nor does this section work correctly.
``
})
export class HeroComponent {
@Input() hero:Hero;
}
hero.ts
export interface Hero {
[id: string]: {
createdAt: number;
isActive: boolean;
title: string;
updatedAt: number;
}
}
Firebase JSON response
{ "-KEMOfA5KFK98AXNhPY0": { "createdAt": 1459607745222, "isActive": true, "title": "Wind Hero", "updatedAt": 1459607745222 } }