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

前端 未结 15 1396
傲寒
傲寒 2020-11-22 09:06

I am new to angular. I am trying to read the uploaded file path from HTML \'file\' field whenever a \'change\' happens on this field. If i use \'onChange\' it works but when

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 09:38

    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 = ''+
                 ' ' +
                 '';
       // 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!!!
        };
    

提交回复
热议问题