title: How to get variable value outside angular function
body: <p>I have been hours trying to understand why I don't get the value of a variable, outside an Angular.js function. First I get the value from a Firebase database, here is my reference :</p>
  
  <pre><code>var refspaedtServ = new Firebase(FBURLSPA + $routeParams.id);
  $scope.spaedServ = $firebaseObject(refspaedtServ);
  </code></pre>
  
  <p>Then I have the function:</p>
  
  <pre><code>        /////  IMAGE REFERENCE  ////
          var lafoto = ''; 
          refspaedtServ.on("value", function(rootSnapshot) {
             lafoto = rootSnapshot.val().foto;
             console.log("Inside image ", lafoto)
         });
  </code></pre>
  
  <p>As you can see, I define my variable 'lafoto' as global
  With the console.log Inside image, I can see the value is correct</p>
  
  <p>But when I try to get the value of "lafoto" variable, outside the function, I'm getting "undefined", I mean no value.</p>
  
  <pre><code>console.log("Outside Image ", lafoto)
  </code></pre>
  
  <p>It seems silly, but I'm reaching madness for that.
  Can anybody give me a hint please?</p>
  
  <p>Regards,
  Victor </p>