Bind JSON object to radio button in angularjs

前端 未结 3 2080
迷失自我
迷失自我 2021-02-05 14:21

So I am trying to bind radio buttons to objects. I have spent like an hour trying to figure this up and at last admit defeat. Here\'s what I got:

3条回答
  •  庸人自扰
    2021-02-05 14:26

    {{theCustomer.name}}
    

    The key here is the ng-value="theCustomer. This is how angular knows which object is selected. The html value only knows string values and cannot map to objects.

    If you insert the above code, the radio will reflect the model, even if it is changed programatically. Also, you can't forget the $parent in the ng-model because the ng-repeat creates a new scope.

提交回复
热议问题