如何隐藏“null"在输入字段Angular 2? [英] How to hide "null" in the input field Angular 2?
本文介绍了如何隐藏“null"在输入字段Angular 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当 JSON 中出现 null 值时,它会出现在输入字段中.我怎样才能隐藏它而不显示它?并只显示名称中的含义?
<输入类型=隐藏"name="roleUserHidden-{{roleIndex}}"#roleUser="ngModel"[ngModel]="role.UserId === 'null' ? '' : role.UserId "/><input [disabled]="!permissions.canEdit"类=形式控制"自动完成[ngModel]="role === 'null' ? '' : role" [source]="usersForAllocationSource.bind(this)"列表格式=名称"name="roleUserAuto-{{roleIndex}}"#roleUserVisible="ngModel"(valueChanged)="usersForAllocationSelected(role, $event, roleUser)"显示属性名称=用户名"[接受用户输入]="假"(ngModelChange)="onRoleUserChange($event, role)"[min-chars]="2">
解决方案
简单的解决方案:
另一种方式:
这是 plunker
的链接When a value of null comes to the JSON, it appears in the input field. How can I hide it and not display it? And to show only the name in the meaning?
<div>
<input type="hidden"
name="roleUserHidden-{{roleIndex}}"
#roleUser="ngModel"
[ngModel]="role.UserId === 'null' ? '' : role.UserId " />
<input [disabled]="!permissions.canEdit"
class="form-control"
auto-complete
[ngModel]="role === 'null' ? '' : role" [source]="usersForAllocationSource.bind(this)"
list-formatter="Name"
name="roleUserAuto-{{roleIndex}}"
#roleUserVisible="ngModel"
(valueChanged)="usersForAllocationSelected(role, $event, roleUser)"
display-property-name="UserName"
[accept-user-input]="false"
(ngModelChange)="onRoleUserChange($event, role)"
[min-chars]="2">
</div>
解决方案
Simple solution :
<input name='name' [ngModel]="obj?.val">
Another way :
<input name='name' [ngModel]="obj.val ? obj.val : '' ">
Here is the link to plunker
这篇关于如何隐藏“null"在输入字段Angular 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文