1
I have a question in Angularjs. To add the values in memory this all ok, but I’m having difficulty subtracting one or more values that are in memory.
$scope.adicionaratividade = function (atividade) {
$scope.atividades.push(angular.copy(atividade));
$scope.total += parseFloat($scope.atividade.tempo);
delete $scope.atividade;
$scope.atividadeForm.$setPristine();
};
$scope.apagaratividades = function (atividades) {
$scope.total -= parseFloat(atividades.tempo);
$scope.atividades = atividades.filter(function (atividade) {
if (!atividade.selecionado) return atividade;
});
};
atividades
is an object or an array? What givesconsole.log(typeof atividades, atividades);
?– Sergio
Sergio is an array
– Marathonasp
Okay, so use it
$scope.total -= parseFloat(atividades.tempo);
will not. What do you want to do in this account?– Sergio
I want to take the total value in memory and subtract from it the value of the deleted item.
– Marathonasp
Okay, and that function
function (atividades)
gives you an array right? So how do you know the ID of the element that will be deleted? is via.selecionado
? (ie all elements of this array with.selecionado
should be taken into account)– Sergio
Sergio put all the code of the page for you to see, so I believe it will be easier for you to understand how I put the logic.
– Marathonasp
Okay, so I go back to the initial question here in the comments. What does
console.log(typeof atividades, atividades);
with the code you have in the question?– Sergio
I ran it on the Chrome Console and gave the following message: VM3550:1 Uncaught Referenceerror: activities is not defined at <Anonymous>:1:32
– Marathonasp
Okay, and if you only use
ng-click="apagaratividades"
What appears on the console?– Sergio
The same error occurs. This is the ultimate goal I want to have with these codes. https://www.evernote.com/shard/s6/sh/6db363ef-f8c1-4d8f-b619-b87889953cdc/ea1c6f7ebbc930e95f8012687fea9be6
– Marathonasp
What do you mean the same mistake appears? I took
atividades
ofng-click
. You can put the mistake here?– Sergio