angular - 如何为多个下拉菜单绑定选定的选项值?
问题描述
我有一个动态数组,例如:说它的长度是 3,在选择下拉列表中的值后会显示另外三个下拉列表。接下来在每个下拉列表中选择值后,应显示每次图像。如果我们有多个下拉菜单,任何人都可以让我知道如何为每个选定的值显示图像。
<div *ngFor="let optionValue of number_axles_array">
Axle {{optionValue}}
<div>
Axle type:<br>
<select [(ngModel)]="optionValue" (change)="onChangeAxle($event.target.value)">
<option *ngFor="let taxel of type_axles_array" [ngValue]="taxel.id">{ taxel.type }}</option>
</select>
<div (ngModel)="optionValue"*ngIf="multipleSelect">
<img src="assets/imagename/name.png">
</div>
</div>
</div>
如果我们有多个下拉菜单,则应为下拉菜单中的每个值显示图像。
解决方案
老实说,我只能假设您想做什么,因为我不清楚您的描述。这里的假设是您希望在每个选择框上选择后显示图像。工作示例在这里
https://stackblitz.com/edit/angular-3hxg2n?file=src/app/app.component.html
而我所做的
模板
<div *ngFor="let selection of selections">
Axle {{selection.value}}
<div >
Axle type:<br> <select [(ngModel)]="selection.value" (change)="onChangeAxle($event.target.value)">
<option *ngFor="let taxel of ['drive','steer']">
{{ taxel }}
</option>
</select>
<div (ngModel)="optionValue" *ngIf="multipleSelect && selection.value">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQS-I2Dee6yl3TqOv7DIeKB0jqHx1gu9xGv4BpSPoDuuvb0ZFQ7">
</div>
</div>
</div>
零件
selections = [];
ngOnInit() {
for (let i = 0; i < 4; i++) {
this.selections.push({
idx:i,
value:""
})
}
}
结果是
推荐阅读
- python-3.x - 在 jupyter 中找不到模块(folium)
- php - Laravel 中的 3 个表关系
- javascript - 发布请求不起作用,声称正文数据不存在
- python - 尝试使用 conda 安装 unrar 时出现 PackagesNotFoundError
- powershell - 部署组作业中的 Powershell 脚本步骤生成此错误:System.Management.Automation.Runspaces.Initializ 的类型初始化程序
- flutter - Dart 单例返回空值
- qt - 如何在 QML 中设置正确的路径到离线 OSM 目录(不使用 qrc)?
- angular - 将 Angular 库的资产文件复制到项目资产文件夹
- java - Spring Boot Web 应用程序的 JSP 页面在作为 war 包托管在外部 tomcat 中时未加载
- c# - Unity 项目无法在 Windows 和 IOS 等 Android 上运行