0
var mainApp = angular.module("mainApp", []);
mainApp.controller('StatsController',function($scope) {
                    Visualforce.remoting.Manager.invokeAction(
                            '{!$RemoteAction.LdAgrStats.getLeadCount}',
                            function(result, event){
                                    if (event.status) {
                                          $scope.$apply(function(){
                                            $scope.count=result;
                                        });
                                        console.log(result);
                                        console.log($scope.count);
                                    } else if (event.type === 'exception') {
                                            $scope.count=0;
                                    } else {
                                            $scope.count=0;
                                    }
                            },
                            {escape: true}
                    );
     });
1

Not much to do with Salesforce. But based purely on the $interval documentation I suggest something like this:

mainApp.controller('StatsController', function($scope, $interval) {

    var action = function() {
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.LdAgrStats.getLeadCount}',
            function(result, event){
                if (event.status) {
                    $scope.$apply(function(){
                        $scope.count=result;
                    });
                    console.log(result);
                    console.log($scope.count);
                } else if (event.type === 'exception') {
                    $scope.count=0;
                } else {
                    $scope.count=0;
                }
            },
            {escape: true}
        );
    };

    // Invoke immediately
    action();

    // Invoke every 10 seconds
    $interval(action, 10000);
});
| improve this answer | |
  • Thanks! its working. but it also waits for that 10 seconds on initial load. when i open the page it is showing scope values after 10 seconds. can you help on that? – vamsi Nov 5 '16 at 20:35
  • @vamsi I've edited the answer to do that. – Keith C Nov 5 '16 at 20:48
  • @vamsi if this solved your problem please do mark it as the correct answer – Eric Nov 6 '16 at 7:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.