【发布时间】:2020-10-05 01:56:36
【问题描述】:
我正在一个预订网站上工作,我有两个选择下拉框,其中包含 3 个相同的城市名称。根据第一个下拉列表中的选择,我希望第二个以不可能具有相等值的方式进行调整。
HTML:
<h4>Airport of Departure</h4>
<select name="" id="">
<option [value]="city" *ngFor="let city of opts">
{{city.key}}
</option>
</select>
<!-- chosen destination -->
<h4>Destination (must be different than departure location)</h4>
<select name="" id="">
<option [value]="city" *ngFor="let city of opts">
{{ city.key }}
</option>
</select>
组件.TS:
public cities = ["Warsaw", "Paris", "New York"];
public opts = [
{ key: "Warsaw", value: ["paris,new york"] },
{ key: "Paris", value: ["warsaw,new york"] },
{ key: "New York", value: ["warsaw, paris,"] }
];
堆栈闪电:https://stackblitz.com/edit/flight-date-pikcer
我在想办法完成这项工作时遇到了麻烦。感谢您的支持!
【问题讨论】:
-
你想在第一个下拉列表的选定值中设置第二个 id 值
-
您需要两个选项源/目的地,绑定到列表。 When the first is selected send event to remove that city from the 2nd.
标签: angular data-binding dropdown option