Jump to content

User:Exploit2016

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Exploit2016 (talk | contribs) at 20:44, 2 November 2016 (Angularflo). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

app.directive('ngFileModel', ['$parse', function ($parse) { return { restrict: 'A', link: function (scope, element, attrs) { var model = $parse(attrs.ngFileModel); var isMultiple = attrs.multiple; var modelSetter = model.assign; element.bind('change', function () { var values = []; angular.forEach(element[0].files, function (item) { var value = { // File Name name: item.name, //File Size size: item.size, //File URL to view url: URL.createObjectURL(item), // File Input Value _file: item }; values.push(value); }); scope.$apply(function () { if (isMultiple) { modelSetter(scope, values); } else { modelSetter(scope, values[0]); } }); }); } }; }]);