<!DOCTYPE html>
<html ng-app="app">
<head>
<script data-require="angular.js@1.5.8" data-semver="1.5.8" src="https://code.angularjs.org/1.5.8/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<root></root>
</body>
</html>
// Code goes here
(() => {
angular
.module('app', [])
.component('root', {
restrict: 'E',
controllerAs: 'vm',
template: `
<div>
<table>
<thead>
<th>name</th>
<th>default</th>
</thead>
<tbody>
<tr ng-repeat="model in vm.models">
<td>
{{model.name}}
</td>
<td>
<input
ng-checked="model.defaulted === true"
type="checkbox"
ng-change="vm.setDefault($index)"
ng-model="model.defaulted" />
</td>
</tr>
</tbody>
</table>
</div>
`,
controller: [function() {
this.models = [
{active: true, name: 'blah', id: 123, defaulted: false},
{active: true, name: 'fdsf', id: 5555, defaulted: false},
{active: true, name: 'cat', id: 5555, defaulted: false},
{active: true, name: 'banana', id: 5555, defaulted: false},
{active: true, name: 'spaghetti', id: 5555, defaulted: false},
{active: true, name: '34r', id: 5555, defaulted: true},
]
this.setDefault = (j) => this.models = this.models.map((m, i) => {
return j === i
? Object.assign({}, m, {defaulted: true})
: Object.assign({}, m, {defaulted: false})
})
}]
})
})()
/* Styles go here */
label, index, span {
display: block;
}
input {
margin-bottom: 15px;
}