title: Why would I wrap a function in AngularJS $timeout service without a delay like they do in ng-file-upload example usage code?
body: <p>In most of the fiddles containing sample usage code for ng-file-upload (<a href="https://github.com/danialfarid/ng-file-upload" rel="noreferrer">https://github.com/danialfarid/ng-file-upload</a>) like the one at (<a href="http://jsfiddle.net/danialfarid/maqbzv15/1118/" rel="noreferrer">http://jsfiddle.net/danialfarid/maqbzv15/1118/</a>), the upload response callback functions wrap their code in a <code>$timeout</code> service call, but these calls do not have any delay parameter passed in.</p>
  
  <p>The Angular.js docs for <code>$timeout</code> (<a href="https://docs.angularjs.org/api/ng/service/" rel="noreferrer">https://docs.angularjs.org/api/ng/service/</a>$timeout) indicate that the delay is optional, but why would you want to make a call to <code>$timeout</code> if not to delay the code being run. In other words instead of the following, why not do the one after:</p>
  
  <pre><code>//inject angular file upload directives and services.
  var app = angular.module('fileUpload', ['ngFileUpload']);
  
  app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $timeout) {
  $scope.uploadPic = function(file) {
  file.upload = Upload.upload({
    url: 'https://angular-file-upload-cors-srv.appspot.com/upload',
    data: {username: $scope.username, file: file},
  });
  
  file.upload.then(function (response) {
    $timeout(function () {
      file.result = response.data;
    });
  }, function (response) {
    if (response.status &gt; 0)
      $scope.errorMsg = response.status + ': ' + response.data;
  }, function (evt) {
    // Math.min is to fix IE which reports 200% sometimes
    file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
  });
  }
  }]);
  </code></pre>
  
  <p>Is there any reason for the <code>$timeout</code> wrapper in all these examples? Would the following file.upload call work in its place?:</p>
  
  <pre><code>file.upload.then(function (response) {
    file.result = response.data;
  }, function (response) {
    if (response.status &gt; 0)
      $scope.errorMsg = response.status + ': ' + response.data;
  }, function (evt) {
    // Math.min is to fix IE which reports 200% sometimes
    file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
  });
  </code></pre>
  
  <p>Edit: I can see that it appears to run without the <code>$timeout</code> wrapper, but the fact it's included in all the examples makes me think it's deliberate, which probably means there's a security/robustness/browser compatibility edge case I don't understand here.</p>