JSFiddle - React, Tailwind, and code Playground
by sqren
HTML
<p>
Select a file, and you should see an alert message
</p>
<div ng-app="myApp" ng-controller="myCtrl">
<input type="file" custom-on-change="uploadFile"/>
</div>
JavaScript
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);
};
});