html - Angular 2 在条件下选择了选项

标签 html select angular

我有一个选择:

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

我想根据条件选择一个选项:'contactType.contactTypeId == number' 而不使用 ngModel

最佳答案

我想这就是你想要的:

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

要删除 selected 属性,您需要返回 null(false 导致 selected="false").

关于html - Angular 2 在条件下选择了选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36750524/

相关文章:

php - strip_tags : strip off the messy tags and styles

css - Internet Explorer 错误解释 html 标签

mysql - 多行的 SQL 条件

c - AF_UNIX 套接字 : select() firing when there is nothing to read

MySQL - 选择然后更新

javascript - 如何创建博客插件?

html - 如何更改 :active link color Twitter Bootstrap

angular - 如何清除 npm 包模块中的 npm 缓存错误?

javascript - Angular 2+ 中 setTimeout 的替代方案

angular - 使用 Angular 路由器切换并保留 ng2-bootstrap <tabset>, <tab> 的选定选项卡