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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -