Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created August 9, 2021 05:52
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 ksakae1216/f41e1a4e467a2f44d20208d4b8e8c13b to your computer and use it in GitHub Desktop.
Save ksakae1216/f41e1a4e467a2f44d20208d4b8e8c13b to your computer and use it in GitHub Desktop.
export class AppComponent implements OnInit {
soccerData = '';
baseballData = '';
constructor(private http: HttpClient){}
ngOnInit():void {
this.getData('soccer');
this.getData('baseball');
}
getData(category: string):void {
let ret = '';
this.http.get<DataObj[]>(`/api/${category}`).subscribe((row) => {
row.forEach((data) => {
ret += `背番号: ${data.id}, 名前: ${data.name}, ボジション: ${data.position}, データ作成日: ${data.createdAt}\n`
});
if (category === 'soccer') {
this.soccerData = ret;
} else {
this.baseballData = ret;
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment