Reputation: 407
Have an app, where i need the 3 x radio-buttons to be independently selected (as a filter functionality).
This is my html:
<div class="dropdown" *ngFor="let type of filterTypes">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{type}}</button>
<div class="dropdown-menu byrd-shade" aria-labelledby="dropdownMenuButton">
<div class="radio-group">
<div class="checkbox-forms gay-flame-forms form-group radio">
<label class="form-check-label">
<div *ngFor="let media of filterMedia">
<input *ngIf="filterMedia"
class="form-check-input"
type="radio"
name="filterMedia"
value="1">
<i aria-hidden="true" class="fa fa-circle"></i>{{media}}
</div>
</label>
</div>
</div>
</div>
TS:
filterTypes: any = ['Media type', 'License type', 'Verification'];
filterMedia: any = ['All', 'Images', 'Videos'];
filterLicense: any = ['All, Exclusive, Non-exclusive'];
filterVerification: any = ['All', 'Verified', 'Non-verified'];
Output:
Am i approaching this wrong? I need the radiobuttons to be singularly (?) active.
Upvotes: 2
Views: 784
Reputation: 102
You can wrap the inputs in a form:
<div class="dropdown" *ngFor="let type of filterTypes">
<button type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">{{type}}</button>
<div class="dropdown-menu byrd-shade" aria-labelledby="dropdownMenuButton">
<div class="radio-group">
<div class="checkbox-forms gay-flame-forms form-group radio">
<label class="form-check-label">
<form>
<div *ngFor="let media of filterMedia">
<input
*ngIf="filterMedia"
class="form-check-input"
type="radio"
name="filterMedia"
value="1">
<i aria-hidden="true" class="fa fa-circle"></i>{{media}}
</div>
</form>
</label>
</div>
</div>
</div>
Hopefully I understood your question and this is what you are looking for.
Upvotes: 0
Reputation: 1456
You are giving all the radio inputs same value, i.e. =1, then how will you distinguish between them. You should bind the value property to a variable depending on your loop iteration like below
<div *ngFor="let media of filterMedia ; let i = index">
<input *ngIf="filterMedia"
class="form-check-input"
type="radio"
name="filterMedia"
[value]="index">
<i aria-hidden="true" class="fa fa-circle"></i>{{media}}
</div>
For three iterations of ngFor, it will create a radio with values 1,2, and 3.That should do the job.
Upvotes: 1