【问题标题】:Angular 2 selected option on conditionAngular 2 在条件下选择了选项
【发布时间】:2016-08-13 12:41:20
【问题描述】:

我有一个选择:

  <select id="position">
    <option *ngFor='#contactType of contactTypes' [attr.value]='contactType.contactTypeId'>
      {{contactType.description}}
    </option>
  </select>

我想在不使用 ngModel

的条件下选择一个选项:'contactType.contactTypeId == number'

【问题讨论】:

    标签: html select angular


    【解决方案1】:

    我想这就是你想要的:

     <select id="position">
        <option *ngFor='#contactType of contactTypes'
          [attr.value]='contactType.contactTypeId' 
          [attr.selected]="contactType.contactTypeId == number ? true : null">
          {{contactType.description}}
        </option>
      </select>
    

    要删除selected 属性,您需要返回nullfalse 会导致selected="false")。

    【讨论】:

      猜你喜欢
      • 2017-10-17
      • 1970-01-01
      • 2017-10-28
      • 2018-05-13
      • 2017-05-20
      • 2016-03-04
      • 1970-01-01
      • 2019-06-18
      • 2017-04-05
      相关资源
      最近更新 更多