-1

I have an item in an object c.data.requiredAttachmentUploaded = false I need to make it "true" when a file is selected in <input type="file" >

So I am trying to do it with ng-change but it's not working, even console.log is not working. Is ng-change is appropriate for this task ?

APP.JS

app.controller('taskSummaryAndAction', [ 
  function() {

    c = this; //declare c internally 
    c.data = {}; //setup our data object (To be used in later steps)

    c.data.requiredAttachmentUploaded = false;

    c.attachmentChange = function() {  
      console.log('Hello');
      c.data.requiredAttachmentUploaded = true;
    }; 

  }
]);

HTML

<div ng-controller="taskSummaryAndAction as c">

    Input File here :

    <input type="file" ng-change="attachmentChange()"
           ng-model="c.data.requiredAttachmentUploaded">

</div>

I can easily do this with jQuery but I need to do this with AngularJS. I m not even getting an error in Console.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • [docs](https://docs.angularjs.org/api/ng/directive/input) says: "*Note: Not every feature offered is available for all input types. Specifically, data binding and event handling via ng-model is unsupported for input[file].*" – barbsan Aug 14 '19 at 07:20
  • ng-change="c.attachmentChange()" – Sagar Chaudhary Aug 14 '19 at 07:21

1 Answers1

0

I made it work, I learnt that usage of ng-change is different for <input type="file" > So I made some change in my controller and my HTML.

JS:

app.controller('taskSummaryAndAction', [ '$scope',
  function($scope) {
    c = this; //declare c internally 
    c.data = {}; //setup our data object (To be used in later steps)
    c.data.requiredAttachmentUploaded = false;

    $scope.attachmentChange = function() {  

      c.data.requiredAttachmentUploaded = true;
      console.log(c.data.requiredAttachmentUploaded);
    }; 

  }
]);

HTML

<input type="file" onchange="angular.element(this).scope().attachmentChange()" ng-model="file">