Home > Mobile >  how to bind boolean value in angular to the api?
how to bind boolean value in angular to the api?

Time:06-01

I have bind value on option button

<select [(ngModel)]="pageInput.isValid">
  <option [value]="true">Valid</option>
  <option [value]="false">Not Valid</option>                            
</select>

2nd.html

<span [hidden]=""
*ngIf="pageInput.isValid== true" >*</span>

when i comparing with this didn't get any change in my result or not showing error, if I comparing value with 'true' as a string I got result but I need value as a Boolean to the api, how can Solved this problem?? please help...

CodePudding user response:

You were almost there:

<option [ngValue]="true">Valid</option>
<option [ngValue]="false">Not-valid</option>

and then you can use this:

<span [hidden]="" *ngIf="pageInput.isValid" >*</span>

and if you want to have the negative one:

<span [hidden]="" *ngIf="!pageInput.isValid" >*</span>
  • Related