Javascript Promises and updating variables
<p>I've been messing with a way to sign in to Spotify and perform <em>most</em> data retrieval from a service in my Ionic app, but a promise is causing the code to pause entirely. </p>

<p>Here is the relevant section from <code>Controllers.js</code>:</p>

<pre><code>  $scope.tracks = [];

  $scope.getTracks = function () {
    var tracks = {},
            i;
        for (i = 0; i &lt; Tracks.uris.length; i++) {
            console.log('Getting Track ' + i);
            tracks[i] = SpotifyService.getTrack(Tracks.uris[i].id, Tracks.uris[i].loved, Tracks.uris[i].from);
        }
        return tracks;
  }

  $scope.refresh = function () {
    console.log('Refresh Tracks Started');
    $scope.tracks = $scope.getTracks().then(function (data) {
      console.log('Getting tracks');
      return data;
    })
    .catch(function (error) {
      console.log(error);
    });
    $scope.$broadcast('scroll.refreshComplete');
  }
</code></pre>

<p>The <code>$scope.refresh()</code> function occurs on a pull to refresh action. This function is called fine, but it stops after the first <code>console.log()</code>. Here is an excerpt from the console (with other loggings):</p>

<pre><code>2016-04-07 14:30:38.419 HelloCordova[8269:377355] updateInfo() data: [object Object]
2016-04-07 14:30:38.419 HelloCordova[8269:377355] Done updating
2016-04-07 14:30:38.419 HelloCordova[8269:377355] getUser() data: [object Object]
2016-04-07 14:30:38.420 HelloCordova[8269:377355] $scope.load() data: [object Object]
2016-04-07 14:30:41.198 HelloCordova[8269:377355] Refresh Tracks Started
</code></pre>

<p>After the last line, nothing else happens and the app is left hanging. Ignore the above lines, they're to do with an earlier problem.</p>

<p>I'm not sure what's happening, it's supposed to retrieve some track data from Spotify, but that logic is all called from within the <code>$scope.getTracks()</code> function which is never called. What have I done wrong?</p>

<p><strong>Edit:</strong> Here's the <code>SpotifyService.getTrack</code> function from <code>Services.js</code>:</p>

<pre><code>getTrack: function(id, loved, from) {
    var storedToken = window.localStorage.getItem('spotify-token');
    if (storedToken !== null) {
      return trackInfo(id).then(function(data) {
          return data;
        })
        .catch(function(error) {
          console.log(error);
        });
    } else {
      login();
    }
  }
</code></pre>