在模板中访问下拉列表的选定值

时间:2017-10-10 16:21:13

标签: angular

如何在模板中访问下拉列表的选定值?

[ValueConversion(typeof(bool), typeof(bool))]
public class PopupIsOpenConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        return values.Any(value => value is bool && (bool) value);
    }
    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
    {
        throw new ActionNotSupportedException();
    }
}

2 个答案:

答案 0 :(得分:1)

你可以得到像这样的选择值:

 <div>
    <select #selectedClient>
      <option *ngFor="let client of clients" [value]="client.id">{{ client.name }}</option>
    </select>
  </div>

  <!-- here I can access clients, but not the selected client -->
  <p>{{selectedClient.value}}</p>

希望它有助于你:)

答案 1 :(得分:0)

你也可以这样做:

  <div>
    <select #dropdown (change)="onDropdownSelect(dropdown)">
      <option *ngFor="let client of clients" [value]="client.id">{{ client.name }}</option>
    </select>
  </div>

在组件中:

  onDropdownSelect(elem){
    console.log(elem.value);
  }