javascript - change a directive not to use jquery api -


i found beautiful directive tosh want. don't wat clear functionality, details of file opened. trying convert this, uses jquery angular native api. attempt here, not working.

http://plnkr.co/edit/i5x3dh?p=preview

any appreciated.

thanks

original:

app.directive('fileselect', function() {   var template = '<input type="file" name="files"/>';   return function( scope, elem, attrs ) {     var selector = $( template );     elem.append(selector);     selector.bind('change', function( event ) {       scope.$apply(function() {         scope[ attrs.fileselect ] = event.originalevent.target.files;       });     });     scope.$watch(attrs.fileselect, function(file) {       selector.val(file);     });   }; }); 

removed need full jquery , made use of angular directive features (the template , 2 way scope variable binding):

app.directive('fileselect', function() {   return {     template:'<input type="file" name="files"/>',     scope:{fileselect:'='},     link:function(scope,el,attrs){       el.bind('change', function( event ) {       scope.$apply(function() {         scope.fileselect = event.target.files;       });     });     }   } }); 

new plnkr: http://plnkr.co/edit/f72ity


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -