Skip to content

Instantly share code, notes, and snippets.

@nerdic-coder
Created May 4, 2018 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdic-coder/9440a6099a8f9d4cd316e6070aafc134 to your computer and use it in GitHub Desktop.
Save nerdic-coder/9440a6099a8f9d4cd316e6070aafc134 to your computer and use it in GitHub Desktop.
dashboard.tsx
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