Created
August 9, 2021 05:52
-
-
Save ksakae1216/f41e1a4e467a2f44d20208d4b8e8c13b to your computer and use it in GitHub Desktop.
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
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