How do I bind to list of checkbox values with AngularJS?

前端 未结 29 2671
天涯浪人
天涯浪人 2020-11-22 05:20

I have a few checkboxes:





        
29条回答
  •  执念已碎
    2020-11-22 06:24

    Since you accepted an answer in which a list was not used, I'll assume the answer to my comment question is "No, it doesn't have to be a list". I also had the impression that maybe you were rending the HTML server side, since "checked" is present in your sample HTML (this would not be needed if ng-model were used to model your checkboxes).

    Anyway, here's what I had in mind when I asked the question, also assuming you were generating the HTML server-side:

    apple orange pear naartjie
    {{checkboxes}}

    ng-init allows server-side generated HTML to initially set certain checkboxes.

    Fiddle.

提交回复
热议问题