Created
May 4, 2018 18:21
-
-
Save nerdic-coder/9440a6099a8f9d4cd316e6070aafc134 to your computer and use it in GitHub Desktop.
dashboard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, State } from '@stencil/core'; | |
import { Hero } from '../../models/hero'; | |
import { HeroService } from '../../services/hero.service'; | |
@Component({ | |
tag: 'app-dashboard', | |
styleUrl: 'dashboard.css' | |
}) | |
export class Dashboard { | |
private heroService: HeroService; | |
@State() private heroes: Hero[]; | |
constructor() { | |
this.heroService = HeroService.Instance; | |
} | |
componentWillLoad() { | |
this.getHeroes(); | |
} | |
getHeroes(): void { | |
this.heroService.getHeroes() | |
.subscribe(heroes => this.heroes = heroes.slice(1, 5)); | |
} | |
render() { | |
return ( | |
<div class='app-dashboard'> | |
<h2>Top Heroes</h2> | |
<div class="grid grid-pad"> | |
{this.heroes ? (this.heroes.map((hero) => | |
<a class="col-1-4"> | |
<div class="module hero"> | |
<h4>{hero.name}</h4> | |
</div> | |
</a> | |
)) : (null)} | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment