Skip to content

Instantly share code, notes, and snippets.

@adityasharat
Created January 28, 2015 17:51
Show Gist options
  • Save adityasharat/4a695df1187bd6bc59cd to your computer and use it in GitHub Desktop.
Save adityasharat/4a695df1187bd6bc59cd to your computer and use it in GitHub Desktop.
AngularJS: loop over some models in the scope and bind them to elements
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Angular</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
</head>
<body>
<div ng-app="RepeatModels" data:ng-controller="appctrl as app">
<ul>
<li data:ng-repeat="model in app.models">
<input type="radio" ng-model="app[model]" value="{{$index+1}}" /> <span data:ng-bind="model"></span>
</li>
</ul>
<div>watch these change</div>
<div data:ng-bind="app.a"></div>
<div data:ng-bind="app.b"></div>
<div data:ng-bind="app.c"></div>
</div>
</body>
<script>
angular.module('RepeatModels', []).controller('appctrl', function () {
this.models = ['a', 'b', 'c'];
this.a = 0;
this.b = 0;
this.c = 0;
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment