3 .directive('fileChange', ['$parse', function($parse) {
7 link: function ($scope, element, attrs, ngModel) {
9 // Get the function provided in the file-change attribute.
10 // Note the attribute has become an angular expression,
11 // which is what we are parsing. The provided handler is
12 // wrapped up in an outer function (attrHandler) - we'll
13 // call the provided event handler inside the handler()
15 var attrHandler = $scope.$eval(attrs.fileChange);
17 // This is a wrapper handler which will be attached to the
19 var handler = function (e) {
21 $scope.$apply(function () {
23 // Execute the provided handler in the directive's scope.
24 // The files variable will be available for consumption
25 // by the event handler.
26 attrHandler($scope, { $event: e, files: e.target.files });
30 // Attach the handler to the HTML change event
31 element[0].addEventListener('change', handler, false);