1

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?

Screenshot of fields showing 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>
3
  • stackoverflow.com/a/43094103/495157 - uses a directive Commented Aug 3, 2017 at 6:14
  • It's not supposed to show 'null' unless it's a string. Commented Aug 3, 2017 at 6:15
  • check for null in ts and assign to the input ngModel Commented Aug 3, 2017 at 6:25

2 Answers 2

4

Simple solution :

<input name='name' [ngModel]="obj?.val">

Another way :

<input name='name' [ngModel]="obj.val ? obj.val  : '' ">

Here is the link to plunker

Sign up to request clarification or add additional context in comments.

Comments

1

If you want to hide the entire input element you can do *ngIf="value" value being whatever is null...

if you want the value to be an empty string you can do [value]="value === 'null' ? '' : value"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.