html5 - Pass angularJS $index into onchange -


i have input file within ng-repeat in angularjs app. need pass $index variable onchange attribute. i'm using onchange , not ng-change because need uploaded object (see post)

in following code 'uncaught referenceerror: $index not defined'

jade code sample:

div.input-group(ng-repeat='filename in filenames track $index')      input(type='file', onchange="angular.element(this).scope().file_changed(this.files, **$index**)") 

in onchange attribute, scope accessible via angular.element(this).scope(). that's method use call file_changed() function, , should use same in order have access $index attribute:

 <input type="file" onchange="angular.element(this).scope().file_changed(this.files, angular.element(this).scope().$index)" /> 

notice becoming pretty long! solution pass dom element function, , obtain informations it:

 <input type="file" onchange="angular.element(this).scope().file_changed(this)" /> 
$scope.file_changed = function (element) {     var index = angular.element(element).scope().$index;     var files = element.files;      // … }; 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -