Skip to content

Instantly share code, notes, and snippets.

@ivoputzer
Last active August 29, 2015 14:08
Show Gist options
  • Save ivoputzer/7065f1fe38e2c835976f to your computer and use it in GitHub Desktop.
Save ivoputzer/7065f1fe38e2c835976f to your computer and use it in GitHub Desktop.
directive to fix file-input field's model binding in angular
.directive('ngFile', ['$parse', function($parse){
return {
restrict: 'A',
require: 'ngModel',
link: function($scope, $element, attrs){
$element.bind('change', function(event){
$scope.$apply(function($scope){
$parse(attrs.ngModel).assign($scope, event.target.files)
})
})
}
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment