Javascript/Angular: Clear Image Select Form Input
All of this is in angular. Without too many boring details, I have an image upload button that doesn't actually upload images. Instead, the 'dummy' form element just passes inform
Solution 1:
clear function should be defined as below
$scope.clear = function () {
angular.element("input[type='file']").val(null);
};
Check the snippet below.
var app = angular.module('myApp', []);
app.controller('myCtrl', ['$scope', function($scope){
$scope.uploadFile = function(){
var file = $scope.myFile;
console.log('file is ' );
console.dir(file);
var uploadUrl = "/fileUpload";
fileUpload.uploadFileToUrl(file, uploadUrl);
};
$scope.clear = function () {
angular.element("input[type='file']").val(null);
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app = "myApp">
<div ng-controller = "myCtrl">
<input type = "file" ng-model = "myFile" file-select="file"/>
<button ng-click="clear()">clear</button>
</div>
</body>
Post a Comment for "Javascript/Angular: Clear Image Select Form Input"