Priti_P 0 Junior Poster

Hello,
I want to stop foreach loop for 5 seconds while processing, in angularjs

But my below code is not working
Where am wrong here?

angular.forEach(data, function(value, key)
{
    total_count=data[key].length; // length of each array
    array_key = key;
    key_length=key.length; // length of each key

    $scope.x_dynamic="Processing " + key;
    ProcessBarService.save_in_new_table(value,array_key)
       .success(function(return_value) {
                                    // on success return, i want stop here for 5 seconds.
                                        if(return_value =='success')
                                        {
                                            total_count=data[key].length ;
                                            incremental_count =100/(Object.keys(data).length ); 
                                            $scope.x_dynamic=key;
                                            setInterval(function()
                                            {
                                                $scope.x_dynamic= key +" Finished " ;
                                            }, 500000000);
                                            $scope.dynamic_success = Math.round( $scope.dynamic + incremental_count) + "% SUCCEEDED";
                                            $scope.dynamic = $scope.dynamic + incremental_count;
                                        }
    });
    // OR it will be ok if i could stop loop here 
});