i have global controller want count elements, because after scope in different html.
'use strict'; angular.module('mainapp') .factory('allinventoryfactory', function ($http, $q, myfactory) { var deferred = $q.defer(); $http({ method: 'get', url: myfactory.urloperation }).success(function (data) { angular.foreach(data, function (datainventary) { var active = 0; var pending = 0; var desactive = 0; var vodafone = 0; var input = datainventary.sites; input.foreach(function (input) { if (input.activationstatus == 'ac') { console.log("ac"); active++; } else if (input.activationstatus == 'pa') { console.log("pa"); pending++; } else if (input.activationstatus == 'de') { console.log("de"); desactive++; } //contracting mode independent of activationstatus if (input.contractingmode == '2') { console.log("vodafone"); vodafone++; } }); }) }).error(function () { deferred.reject('there error') }) return deferred.promise; }); the global result of each counter 0, code doesn't increment number. , don't know how can continue.
you need put declaration of counting variables out of loop. otherwise declarated , initialized 0 everytime loop through.
Comments
Post a Comment