Skip to content

Instantly share code, notes, and snippets.

@ismcagdas
Created January 30, 2018 13:01
Show Gist options
  • Save ismcagdas/e3416747eea75e37775ed760af8118a5 to your computer and use it in GitHub Desktop.
Save ismcagdas/e3416747eea75e37775ed760af8118a5 to your computer and use it in GitHub Desktop.
Acme.HeroShop - app.component.ts - 4
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
heroCompanies: any = [];
originalHeroes: any = [];
displayHeroes: any = [];
selectedHeroCompany: string = 'All';
ngOnInit(): void {
this.heroCompanies = (window as any).TRANSFER_CACHE.fromDotnet.heroCompanies;
this.originalHeroes = (window as any).TRANSFER_CACHE.fromDotnet.heroes;
this.displayHeroes = (window as any).TRANSFER_CACHE.fromDotnet.heroes;
}
filterHeroes(heroCompanyId: number): void {
if (!heroCompanyId) {
this.displayHeroes = this.originalHeroes;
this.selectedHeroCompany = 'All';
} else {
this.displayHeroes = this.originalHeroes.filter(hero => hero.heroCompanyId === heroCompanyId);
this.selectedHeroCompany = this.heroCompanies.filter(heroCompany => heroCompany.id === heroCompanyId)[0].name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment