0

I have the following problem. The $watch event gets called when I manually select a file. But when I do it by using the following

$scope.clear = function() {
    $scope.logo = null;
  };

it doesn't fire the event. Any ideas?

Here's the plunkr

Shak Ham
  • 1,209
  • 2
  • 9
  • 27
  • neither does ng-change, because the changes made in javascript are not watched by angular. – harishr Aug 27 '14 at 18:56
  • Here's a plunkr that is similar to what I want:http://plnkr.co/edit/xLM9VX?p=preview How can I modify it to have scope variable like document – Shak Ham Aug 27 '14 at 18:57

1 Answers1

0

the problem is with input type file. the input type[file] does not get reset as other inputs do.

please read more about this here and here.

the suggested solution is:

<input type="file" id="control"/>

and corrosponding js

var control = $("#control");

$("#clear").on("click", function () {
    control.replaceWith( control = control.clone( true ) );
});

you can always write a directive which would make it much more reusable.

Community
  • 1
  • 1
harishr
  • 17,807
  • 9
  • 78
  • 125
  • why this plunkr works plnkr.co/edit/xLM9VX?p=preview ? The event gets called when you click on the clear button. – Shak Ham Aug 27 '14 at 19:15