Reputation: 115
How can I open the select
when I click on the label
?
<label>filter per category: <span>{{ articleListService.selectedCategory }}</span></label>
<select #category (change)="articleListService.categoryFilter2()" [(ngModel)]="articleListService.formModel.category">
<option value="">All</option>
<option *ngFor="let category of articleListService.laCategoryList" value="{{ category.id }}">
{{ category.name }}
</option>
</select>
Thank you for you help, i'm lost
Upvotes: 5
Views: 4999
Reputation: 35
Good question, this is more of an HTML 5 thing then an Angular thing. You are going to want to use a for={id}
.
So in your specific code, it would look something like this.
<label for="category">filter per category: [cat group shows here]</label>
<select id="category" #category (change)="articleListService.categoryFilter2()" [(ngModel)]="articleListService.formModel.category">
<option value="">All</option>
<option *ngFor="let category of articleListService.laCategoryList" value="{{category.id }}">
{{ category.name }}
</option>
</select>
Upvotes: 1
Reputation: 2580
Found an article that is similar to what you're asking but you have to have the label as a parent of the select?
https://medium.com/browserquirks/browserquirk-programmatically-opening-a-select-box-4ca745a8468f
or maybe try adding a template reference to the select, and then @ViewChild('ThatReference') thatRef: ElementRef;
then maybe when you click label, and it fires event to trigger click event on select via this.thatRef.nativeElement.click()
?
Upvotes: 0