3

I have a file input

<input type="file" ng-change="action()">

Now in my controller I dont want to do selectors and stuff. so I just have

$scope.action = () -> 
  ...

However, I want a certain behavior such that as long as user selects a File the $scope.action is called, instead of onchange is there onselect event in angular?

Louis
  • 146,715
  • 28
  • 274
  • 320
user2167582
  • 5,986
  • 13
  • 64
  • 121
  • 1
    possible duplicate of [AngularJs: How to check for changes in file input fields?](http://stackoverflow.com/questions/17922557/angularjs-how-to-check-for-changes-in-file-input-fields) – Josep Oct 29 '14 at 21:22
  • not quite the fix I was hoping for, but onchange is a better way as ng-change listens for the model. either way clearing this input is a must, it seems like. – user2167582 Oct 30 '14 at 20:44

1 Answers1

8

Use thisss

<input ng-model="photo"
       onchange="angular.element(this).scope().file_changed(this)"
       type="file" accept="image/*" />


$scope.file_changed = function(element, $scope) {

     $scope.$apply(function(scope) {

     });
});
Harutyun Abgaryan
  • 2,013
  • 1
  • 12
  • 15
  • the actualy resolution i got was to use document.select(input).text = "" to reset the content. – user2167582 Nov 27 '14 at 22:20
  • 2
    This is a bad way to do it, see explanation here : http://stackoverflow.com/questions/17922557/angularjs-how-to-check-for-changes-in-file-input-fields#comment43502160_17923521 – Link14 Jul 01 '16 at 02:32