title: Angular $scope data wont update
body: <p>Im writing an application which connects to a 3rd party api.</p>
  
  <p>The api uses a auth token system so i have an async node js function which first requests the token and then uses that token to retrieve some data.</p>
  
  <p>The problem is that when the data changes the angualr $scope wont update so the page will show the same data even if an error is thrown in the node js api call.</p>
  
  <p>A little run through the code.</p>
  
  <p>get-salesLead-data.js Has a Async waterfall function which firsts calls the 3rd party rest api using http PUT and returns an auth token. This token is then passed into the second function of the Async water which is then used to make a http GET request to get the sales lead data. </p>
  
  <p>Here is the Node Async api call.</p>
  
  <pre><code>    **get-saleLead-data.js** 
  
      // app/get-SalesLead-data.js
      // modules =================================================
  
      var http = require('http');
      var express = require('express')
      var async = require('async');
  
      module.exports = function(app) {
  
  
         Using async to preform async api calls and passing data between them
  
          async.waterfall([
  
              // First function is requesting the auth token
  
              requestToken = function(callback) {
  
                  var options = {
                      "host": "********",
                      "path": '************'
                      "method": "PUT",
                      "headers": {
                          "Content-Type": "application/json",
                      }
                  };
  
                  var login = JSON.stringify({
  
                      "username": "********",
  
                      "password": "********",
  
                      "client_ip_address": "********"
  
                  });
  
                  var req = http.request(options, function(res) {
                      res.on('data', function(body) {
                          var body = JSON.parse(body);
                          var token = body.token;
                          console.log(token);
                          callback(null, token);
                      });
                  });
  
                  req.on('error', function(e) {
                      console.log('problem with request: ' + e.message);
                  });
  
                  req.write(login);
                  req.end();
              },
  
              // Second function is using the auth token receieved from the first function to get sales lead dat
              getData = function(arg1, callback) {
  
                  // Geting the sales id from the url and using it in the api request.
                  app.get('/', function(req, res) {
  
                      app.set('salesLeadId', req.query.id);
                      var token = arg1;
                      var auth = 'Basic ' + new Buffer('********' + ':' + token).toString('base64');
                      var path = '****************' + app.get('salesLeadId');
                      var options = {
                          "host": "********",
                          "path": path,
                          "method": "GET",
                          "headers": {
                              "Content-Type": "application/json",
                              "Authorization": auth
                          }
                      };
  
                      var data = '';
  
                      // Assinging response data to to data
                      var req = http.request(options, function(res) {
                          res.on('data', function(chunk) {
                              data += chunk;
                          });
  
                          // Creating sales lead api so the front end can make requests
                          res.on('end', function(res) {
                              var body = JSON.parse(data);
                              console.log(body);
                              app.get('/api/salesLead', function(req, res) {
                                  return res.json(body);
                                  $scope.$apply();
                              });
  
                          })
  
                      });
  
                      req.on('error', function() {
                          alert('error');
                      });
  
  
                      res.sendFile('index.html', {
                          root: '../vpbx/public/views'
                      });
  
                      req.end();
  
                  });
  
              }
  
          ], function(err, result) {
  
          });
      };
  </code></pre>
  
  <p>Below is the service which accesses /api/salesLead
  Creating a function which calls the backend usinga  http GET request. This then returns the sales lead data.</p>
  
  <pre><code>**salesLeadService.js**
  
      angular.module('SalesLeadService', []).service('SalesLeadService', function($http, $location, $rootScope) {
  
          var urlBase = '/api/salesLead'
  
          this.getSalesLead = function (data) {
              return $http.get(urlBase, data)
          };
      });
  </code></pre>
  
  <p>below is the offer controller. This calls the service above and assigns the data to the <code>$scope.salesLead</code>.</p>
  
  <pre><code>**offer.js**
  
      // Form controller
      // =============================================================================
      angular.module('offerController', []).controller('offerController', function($scope, $http, SalesLeadService, $timeout) {
  
          // GETTING THE DATE-TIME STAMP
          $scope.getDate = new Date();
          $scope.date = Date();
  
          // CALLING THE FUNCTION FROM THE SALES LEAD SERVICE
  
          SalesLeadService.getSalesLead()
              .then(function(response) {
                      $scope.salesLead = response.data;
                      $scope.$applyAsync();
              });
      });
  </code></pre>
  
  <p>Just a note that i have tried using <code>$scope.$apply</code> but havnt had any luck.
  Any help is appreciated
  Thanks</p>