Skip to content

Instantly share code, notes, and snippets.

@mpdaugherty
Created July 7, 2012 06:23
Show Gist options
  • Save mpdaugherty/3065072 to your computer and use it in GitHub Desktop.
Save mpdaugherty/3065072 to your computer and use it in GitHub Desktop.
Example of how to correctly use radio inputs with Angular JS's ng:Repeat directive
<div ng-repeat="m in milestone_choices" class="row-fluid">
<label><input type="radio" name="meaningless" value="(( $index ))" ng-model="milestone_data.index" />
&nbsp;<span ng-bind="m.title"></span></label>
</div>
$scope.milestone_data = { index: 0 };
<input name="milestone" type="hidden" value="(( repo.name + '--milestone--' + milestone.number ))"/>
<select ng-show="milestone_choices.length"
ng-model="milestone" ng-options="m.title for m in milestone_choices">
</select>
<div ng-repeat="milestone in milestone_choices" class="row-fluid">
<input type="radio" ng-model="milestone" name="milestone" value="(( repo.name + '--milestone--' + milestone.number ))" ng-model="milestone"/>
&nbsp;<span ng-bind="milestone.title"></span>
</div>
@ernestopye
Copy link

The name attribute for radio buttons isn't meaningless. If you have multiple radio button lists they won't group properly, will they? I had to bind a unique group value to mine to get them to work.

@klebergraciasoares
Copy link

Top

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment