Created
January 30, 2018 13:01
-
-
Save ismcagdas/e3416747eea75e37775ed760af8118a5 to your computer and use it in GitHub Desktop.
Acme.HeroShop - app.component.ts - 4
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, 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