I am turning to angularjs, but the learning curve is seeming a bit hard :((
Look at the following fiddle:
http://jsfiddle.net/ereallstaff/QgEx9/
I have 2 problems: 1- the class does not reflect the if statement ng class
ng-class="{'selectedRow': p.is_active}
2 - I need to make a flow to save on db only selected item by end user. usually with jquery I do a checkbox applying a class, and if the class is found I send datas to server.
In this case with 2 way binding, I just image I need to remove the element from the $scope.data model to send to server and it should be fine.
But while the element is removed correctly, the length of the model keep staying to 5, while it should decrease!
Thanks*emphasized text*
Your condition should look something like this:
ng-class="{'selectedRow': p.is_active == '1' }
otherwise the 'selectedRow' class will be added even if p.is_active is '0'.
Before sending the information to the server, filter the items that are selected (by checking the is_active value):
$scope.selectedOnes = function() {
var result = [];
angular.forEach($scope.personnel, function(entry) {
if (entry.is_active == '1') {
result.push(entry);
}
});
return result;
};
Also note that '1' != 1 (string != number).
jsfiddle: http://jsfiddle.net/bmleite/Yjcgh/