1
var ecm = '';
$http.get('v1/xys/')
              .success(function(res){

                if($route.current.$$route.controller == 'historial')
                 {
                  return ecm = {
                    'cc' : cc,
                    'purchase' : {
                      'field' : field,
                        'prd' : result
                   }
                  }  
                 }else{
                  return ecm = {
                    'purchase' : {
                      'field' : '',
                        'prd' : []
                   }
                 }
                }


              }).error(function(err){

              })

console.log(ecm);

//how can i access the ecm object outside http request. I did return but does not work is there any other process to come over this issue. please guide thanks a ton in advance.

Saurav
  • 27
  • 5

1 Answers1

0

try this:

    var ecm = {};
    $http.get('v1/xys/')
         .success(function(res){

                  if($route.current.$$route.controller == 'historial')
                  {
                     ecm = {
                        'cc' : cc,
                        'purchase' : {
                        'field' : field,
                        'prd' : result
                         }
                      }  
                   } else{
                      ecm = {
                        'purchase' : {
                        'field' : '',
                        'prd' : []
                       }
                   }
           }  
           }).error(function(err){
                      ecm = {
                        'cc' : 'Error occurred',
                        'purchase' : 'Error occurred'
                      } 
});

    console.log(ecm);
Hasan Nafisi
  • 138
  • 6