Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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 I use it angular way using 'ng-change' it doesn't work.

<script> 

var DemoModule = angular.module("Demo",[]); 

DemoModule .controller("form-cntlr",function($scope){

$scope.selectFile = function() 

{

 $("#file").click(); 

$scope.fileNameChaged = function() 

alert("select file"); 

}); 

</script> 

<div ng-controller="form-cntlr"> 

<form> 

 <button ng-click="selectFile()">Upload Your File</button> 

 <input type="file" style="display:none" 

id="file" name='file' ng-Change="fileNameChaged()"/> </form> 

</div>

fileNameChaged() is never called. Firebug also doesn't show any error.

1 Answer

0 votes
by (106k points)

For checking the changes in file input fields you can replace the following lines with another code which I am mentioning in the second part:-

<input type="file" style="display:none" id="file" name='file' ng-Change="fileNameChanged()" />

You should use these lines of code:-

<input type="file" style="display:none" id="file" name='file' onchange="angular.element(this).scope().fileNameChanged()" />

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 29, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...