我有下面这段代码:
<table class="details-table" *ngIf="animal && animaldata">
<tr *ngFor="let attribute of animaldata.Attributes">
<td class="details-property">{{ attribute.AttributeLabel }}</td>
<td [ngSwitch]="attribute.AttributeType">
<div *ngSwitchCase="'String'">
<input *ngIf="attribute.IsWritable" matInput [(ngModel)] = "animal[attribute.AttributeKey]" />
<span *ngIf="!attribute.IsWritable && attribute.IsReadable">{{ animal[attribute.AttributeKey] }}</span>
</div>
<div *ngSwitchCase="'Boolean'">
**{help needed}**
<div *ngSwitchDefault>{{ animal[attribute.AttributeKey] }}
</div>
</td>
</tr>
</table>
我想根据属性的类型显示不同的输入字段(例如: string,boolean,Integer ),基于它是否可写。我有一个字符串的想法,但我想做一个布尔值的下拉列表。另外,它只是Integer的纯文本吗?我尝试了几个我在网上找到的下拉列表的例子,但我觉得我做错了什么。有没有人能提供一个可以实现的想法?还有人能评论一下,这是不是可以简化代码的正确方法?任何帮助都是非常感谢的。
谢谢
发布于 2018-08-14 07:54:30
您可以轻松地设置下拉列表,如下所示
<div *ngSwitchCase="'Boolean'">
<select *ngIf="attribute.IsWritable" [(ngModel)]="yourProperty">
<option (value)="1">Select One</option>
<option (value)="2">Select Two</option>
</select>
<span *ngIf="!attribute.IsWritable && attribute.IsReadable">{{
animal[attribute.AttributeKey] }}</span>
看起来你错过了结束的div
https://stackoverflow.com/questions/51831577
复制相似问题