Skip to content

Instantly share code, notes, and snippets.

Created May 13, 2011 17:20
Show Gist options
  • Save anonymous/970934 to your computer and use it in GitHub Desktop.
Save anonymous/970934 to your computer and use it in GitHub Desktop.
Angular: Workaround for initializing radio buttons when using ng:repeat
<html>
<head>
<script src="http://code.angularjs.org/angular-0.9.13.js" ng:autobind></script>
<script>
function MyCntrl() {
this.list_of_items = ['this', 'that', 'the other'];
this.foo = {choice: 'that'};
}
MyCntrl.prototype.check = function(value) {
return value == this.foo.choice;
}
</script>
</head>
<body ng:controller="MyCntrl">
<ul>
<li ng:repeat="item in list_of_items">
<input type="radio" name="foo.choice" value="{{item}}"
id="item_{{$index}}" checked="{{check(item)}}">
<label for="item_{{$index}}">
<code>{{item}}</code>
</label>
</li>
</ul>
choice: {{foo.choice}}
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment