我试图在带文件类型的输入元素上使用ng-model。我找到了this示例,但仍然不知道如何将其转换为ES6并使用它(将其置于ng-model或sth)。
var myApp = angular.module('myApp', []);
myApp.directive('customOnChange', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var onChangeFunc = scope.$eval(attrs.customOnChange);
element.bind('change', onChangeFunc);
}
};
});
myApp.controller('myCtrl', function($scope) {
$scope.uploadFile = function(){
var filename = event.target.files[0].name;
alert('file was selected: ' + filename);
};
});