當null值到達JSON時,它將出現在輸入字段中。我如何隱藏它並不顯示它?並只顯示名稱中的含義?如何在輸入字段Angular 2中隱藏「null」?
<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>
https://stackoverflow.com/a/43094103/495157 - 使用指令 – JGFMK
除非是字符串,否則不應該顯示'null'。 –
在ts中檢查空值並分配給輸入ngModel – Sreemat