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

前端 未结 15 1540
傲寒
傲寒 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:34

    I have done it like this;

    
    
    
    
    // self is the instance of $scope or this
    self.upload = function () {
       var ctrl = angular.element("#txtUploadFile");
       ctrl.on('change', fileNameChanged);
       ctrl.click();
    }
    
    function fileNameChanged(e) {
        console.log(self.currentItem);
        alert("select file");
    }
    

提交回复
热议问题