I'm trying to mark as a default a radiobutton depending on the value I get from my object, it can be True or False. What could I do to mark as a default radiobutton depending on the option?
<label>This rule is true if:</label>
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="mode" value="true"
[(ngModel)]="rule.mode"> all of the following conditions are true
</label>
<label class="form-check-inline">
<input class="form-check-input" type="radio" name="mode" value="false"
[(ngModel)]="rule.mode"> at least one of the following conditions is true
</label>
I have the true or false set in rule.mode
.
We can use [(ngModel)] in following way and have a value selection variable radioSelected
Example tutorial
Demo Link
app.component.html
app.component.ts
Sample Data for Listing
You can use
[(ngModel)]
, but you'll need to update yourvalue
to[value]
otherwise the value is evaluating as a string. It would look like this:If
rule.mode
is true, then that radio is selected. If it's false, then the other.The difference really comes down to the
value
.value="true"
really evaluates to the string 'true', whereas[value]="true"
evaluates to the boolean true.