使用AngularJS运行时中的资源更新控制器中的值

时间:2021-09-21 21:18:57

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

我想将$ scope.totalchatsdone作为整数

Edit :- console pic-- i dont know why i is 0 here,see in console please(why it is not taking total value ?? )... 使用AngularJS运行时中的资源更新控制器中的值

编辑: - 控制台图片 - 我不知道为什么我在这里0,请在控制台中看到(为什么它没有采取总价值?)...

1 个解决方案

#1


1  

query() behaves as a promise, i.e before your execution of each loop is completed. Your variable i get consoled.

query()表现为一个promise,即在完成每个循环的执行之前。你的变量我得到了安慰。

#1


1  

query() behaves as a promise, i.e before your execution of each loop is completed. Your variable i get consoled.

query()表现为一个promise,即在完成每个循环的执行之前。你的变量我得到了安慰。