title: Trigger input file click event in AngularJS
body: <p>I am trying to emulate a click event on a file input in AngularJS. I have seen <a href="http://jsfiddle.net/fEBFp/1/" rel="noreferrer">working jQuery examples</a>, but I don't want to use jQuery.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>'use strict';
  
  angular.module('MyApp', []).
  
  controller('MyCtrl', function($scope) {
    $scope.click = function() {
      setTimeout(function() {
        var element = angular.element(document.getElementById('input'));
        element.triggerHandler('click');
        $scope.clicked = true;
      }, 0);
    };
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://code.angularjs.org/1.3.14/angular.js"&gt;&lt;/script&gt;
  &lt;div ng-app="MyApp" ng-controller="MyCtrl"&gt;
    &lt;input id="input" type="file"/&gt;
    &lt;button ng-click="click()"&gt;Click me!&lt;/button&gt;
    &lt;div ng-if="clicked"&gt;Clicked&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Note: For some reason the button needs to be pressed twice in order to trigger the timeout function.</p>
  
  <p>I am using <code>setTimeout</code> because of <a href="https://stackoverflow.com/a/19519023/1154610">this post</a>.</p>
  
  <p>How do I programmatically click a file input with just AngularJS / vanilla JavaScript?</p>