首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >基于Html中的类型的输入

基于Html中的类型的输入
EN

Stack Overflow用户
提问于 2018-08-14 06:50:49
回答 1查看 41关注 0票数 0

我有下面这段代码:

代码语言:javascript
复制
<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的纯文本吗?我尝试了几个我在网上找到的下拉列表的例子,但我觉得我做错了什么。有没有人能提供一个可以实现的想法?还有人能评论一下,这是不是可以简化代码的正确方法?任何帮助都是非常感谢的。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-14 07:54:30

您可以轻松地设置下拉列表,如下所示

代码语言:javascript
复制
<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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51831577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档