Updating a value in a controller using a resource in angulaj runtime

My controller code

//first $http request to get results.wesites
// i want to get $scope.totalchatsdone as an integer dont know how 
$scope.totalchatsdone  = function (){  
    var i =0;
    $.each(results.websites,function(index,website){
    var id = website.id;
    $scope.tech = techRepository.getTech.query({ id }, function(data) {
        console.log("total--"+ data.total)
        i += data.total;
    });
});
console.log("i is--"+i)
return i;
};

my factory code

factory('techRepository', ['$resource', function ($resource,$http) {
    return {
        getTech: $resource(base_url+'/testapi/chats/:id', {id: '@id'}, {query: {method: 'GET'}})
    };
}])         

What I want: -

I want to get $ scope.totalchatsdone as an integer

Edit: - console pic-- I don't know why I am here 0, see the console, please (why doesn’t it accept the total cost?) ... enter image description here

+4
source share
1 answer

query()behaves like a promise, that is, until the end of each cycle. Your variablei will receive comfort.

+1
source

All Articles