Having this table row in mind, I'm trying to dynamically enable/disable the appropriate checkboxes:
function enableTheRoles(data){
var myRoles = [
{role1: true, name: "Role One", enabled: true},
{role2: false, name: "Role Two", enabled: false},
{role3: true, name: "Role Three", enabled: true},
{role4: false, name: "Role Four", enabled: false},
{role5: true, name: "Role Five", enabled: true},
{role6: false, name: "Role Six", enabled: false},
{role7: true, name: "Role Seven", enabled: true},
{role8: false, name: "Role Eight", enabled: false},
{role9: true, name: "Role Nine", enabled: true},
{role10: false, name: "Role Ten", enabled: false}
];
}
<tr>
<td>
<input type="checkbox" name="role1" ng-model="ctrl.data.roles.role1" /> Role One
</td>
<td>
<input type="checkbox" name="role2" ng-model="ctrl.data.roles.role2" /> Role Two
</td>
<td>
<input type="checkbox" name="role3" ng-model="ctrl.data.roles.role3" /> Role Three
</td>
<td>
<input type="checkbox" name="role4" ng-model="ctrl.data.roles.role4" /> Role Four<
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="role5" ng-model="ctrl.data.roles.role5" /> Role Five
</td>
<td>role six</td>
<td>role seven</td>
<td>role eight</td>
</tr>
So far I've managed to iterate the source data (coming back from an Angular service), and create a new array entitled myRoles
.
I'd like to now tie the myRoles
array to the checkbox
inputs on my view, and therefore enable/disable accordingly.
So in other words, if the "Role One" checkbox should be enabled
, then ng-model=ctrl.data.roles.role1
should pick up the enabled
property from the myRoles
array.
Perhaps iterating thru ng-model ?
Any advice is appreciated. In the meantime, I will research ...