I am trying to change a boolean value when a user clicks on a table row that is populated with JSON. For example I have this...
$scope.prices = {
"Prices": [
{
"Code": "edl",
"Selected": false
},
{
"Code": "ead",
"Selected": false
}
]
}
Which I then bind to a table...
<table>
<tr ng-click="change(item.code)" ng-repeat="item in prices">
<td>{{prices.Code}}</td>
</tr>
</table>
And when a user clicks on a row the change function is fired that would then change the selected value to either true or false
$scope.change = function (itemCode) {
//update the clicked code selcted value to True/False
// first check if its true or false
// then change it accordingly
// Please excuse my terrible attempt!
if(!$scope.prices.code.selected){
$scope.prices.code.selected = true
} else {
$scope.prices.code.selected = false
}
};
As I'm not sure how to achieve this from the change function. Or is there another way? Thanks
ng-repeatisn't used properly either