[英]how do I dynamically add options to a select tag based on array data?
This is what I have这就是我所拥有的
mypage.component.html mypage.component.html
<select>
<option>2 weeks</option>
<option>1 Month </option>
<option>6 Months</option>
</select>
mypage.component.ts mypage.component.ts
export class MyPageComponent implements OnInit {
constructor() { }
public searchDates: Array<String> = [ "1 week", "2 weeks" ];
ngOnInit(): void { }
}
How do I replace the hard coded options with content from the searchDates array?如何用 searchDates 数组中的内容替换硬编码选项? assuming the array will change in size from time to time.
假设数组会不时改变大小。
Use ngFor
:使用
ngFor
:
<select>
<option *ngFor="let a of searchDates">
{{a}}
</option>
</select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.