public optionsList: any[] = [];
ngOnInit(): void {
this.myService.getOptions().subscribe(
response => {
this.optionsList = response;
},
error => {
console.log(error);
}
);
}
其中,ngFor指令会循环遍历optionsList中的所有数据,并将每个数据的value属性作为下拉选项的值,label属性作为下拉选项的显示文本。
其中,selectedOption变量保存了用户选择的下拉选项的值。