Warm tip: This article is reproduced from stackoverflow.com, please click
angular html

The checkbox next to the text does not get enabled on click, it's always the first one

发布于 2020-03-31 22:57:56

enter image description hereI arranged the checkboxes and the text right next to each other using bootstrap grid. But, when I click on the textbox other than the first one, only the first checkbox gets enabled. How do I make the respective checkboxes get enabled without distorting the order?


Here is my stackblitz url

Questioner
Shivani
Viewed
21
Rounak Snehasis 2020-01-31 20:37

The stackblitz is not working properly but one thing you can try is making the id of the checkboxes unique like component-

public routes=[{"id":1, "place":"Chennai - 500085/Madhapur, TS"}, {"id":2, 
"place":"chennai-mumbai"}, {"id":3, "place":"chennai-madhapur"}, {"id":4, 
"place":"chennai-secundrabad"}];

html-

<div class="col-sm-1" style="margin-top: 10px;">
                    <mat-checkbox class="check-style" id="route.id"></mat-checkbox>
                </div>
                <div class="col-sm-10">
                    <div class="routesList">
                        {{route.place}}
                    </div>
                </div>

I hope it helps.