Subtract

Asked

Viewed 126 times

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 gives console.log(typeof atividades, atividades);?

  • Sergio is an array

  • Okay, so use it $scope.total -= parseFloat(atividades.tempo); will not. What do you want to do in this account?

  • I want to take the total value in memory and subtract from it the value of the deleted item.

  • 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 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.

  • 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?

  • I ran it on the Chrome Console and gave the following message: VM3550:1 Uncaught Referenceerror: activities is not defined at <Anonymous>:1:32

  • Okay, and if you only use ng-click="apagaratividades" What appears on the console?

  • 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

  • What do you mean the same mistake appears? I took atividades of ng-click. You can put the mistake here?

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.