Created
May 13, 2011 17:20
-
-
Save anonymous/970934 to your computer and use it in GitHub Desktop.
Angular: Workaround for initializing radio buttons when using ng:repeat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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