【发布时间】:2019-08-02 21:34:41
【问题描述】:
我已经搜索过很多地方。我从other answers 得到的是,如果我想选择一个特定的选项,我需要使用[selected]。
它似乎不起作用。为什么? 这是我所拥有的:
<ngx-datatable-column name="status" prop="operationStatus" [flexGrow]="1">
<ng-template let-value="value2" let-row="row" let-rowIndex="rowIndex" gx-datatable-cell-template>
<select class="geraeteStatus" [(ngModel)]="selectableGerateStatus">
<option *ngFor="let e of selectableGerateStatus" [ngValue]="e"
[selected]="e.id === value2">
{{e.id}}
</option>
</select>
</ng-template>
</ngx-datatable-column>
我确信e.id 的值每次迭代至少等于value2 的值一次。然而,它只是不起作用。
实际上,我可以将任何我想要的(e.id === 2,甚至'true')放入[selected],它没有任何效果。
我不知道我错过了什么。任何答案都非常感谢。
【问题讨论】:
-
如果您使用的是 [(ngModel)],则不得使用 [selected]。问题是您使用的是 [ngValue]="e"。所以,变量“selectableGenerateStatus”是一个对象——你真的需要它是同一个对象。使用 [ngValue]="e.id" 工作
-
好的,我明白了。我删除了“选定”。我更改为以下内容: 。但是还是不行
标签: angular select html-select