[angularjs] AngularJs: How to check for changes in file input fields?

Too complete solution base on:

`onchange="angular.element(this).scope().UpLoadFile(this.files)"`

A simple way to hide the input field and replace it with a image, here after a solution, that also require a hack on angular but that do the job [TriggerEvent does not work as expected]

The solution:

  • place the input-field in display:none [the input field exist in the DOM but is not visible]
  • place your image right after On the image use nb-click() to activate a method

When the image is clicked simulate a DOM action 'click' on the input field. Et voilĂ !

 var tmpl = '<input type="file" id="{{name}}-filein"' + 
             'onchange="angular.element(this).scope().UpLoadFile(this.files)"' +
             ' multiple accept="{{mime}}/*" style="display:none" placeholder="{{placeholder}}">'+
             ' <img id="{{name}}-img" src="{{icon}}" ng-click="clicked()">' +
             '';
   // Image was clicked let's simulate an input (file) click
   scope.inputElem = elem.find('input'); // find input in directive
   scope.clicked = function () {
         console.log ('Image clicked');
         scope.inputElem[0].click(); // Warning Angular TriggerEvent does not work!!!
    };