簡體   English   中英

成功提交表單后,輸入類型文件未清除

[英]Input type file is not clearing up when successfully submitting the form

當我提交表單時,輸入文本正在清除,但上傳的文件未清除。 我已經使用$ scope.addAnswerForm。$ setPristine(); 但這不起作用。

  app.directive('fileModel', ['$parse', function($parse) { return { restrict: 'A', link: function(scope, element, attrs) { var model = $parse(attrs.fileModel); var modelSetter = model.assign; element.bind('change', function() { scope.$apply(function() { modelSetter(scope, element[0].files[0]); }); }); } }; } ]); app.controller("MyCtrl", function($scope, $http) { $scope._answer = { text: '', comment_pic: '' }; $scope.__answer = JSON.parse(JSON.stringify($scope._answer)); $scope.addAnswer = function(todo) { var data = { answer: $scope.__answer.text, comment_pic: $scope.__answer.comment_pic, }; var fd = new FormData(); for (var key in data) { fd.append(key, data[key]) }; $http({ url: '/posturl' data: fd, method: "POST", headers: { 'Content-Type': undefined } }).success(function(data, status) { todo.answers.push($scope.__answer); $scope._answer.comment_pic = ""; $scope.__answer = JSON.parse(JSON.stringify($scope._answer)); }); }; }); 
 <div ng-controller="myCtrl"> <form name="addAnswerForm"> <input ng-model="__answer.text" /> <input type="file" file-model="__answer.comment_pic" /> <button type="submit" ng-click="addAnswer(discussion)">Post</button> </form> </div> 

提交表單后如何使表單清晰此輸入type =“ file”中的文件未被清除 在此處輸入圖片說明

通過清除表單的DOM,可以清除表單。

document.getElementById(“ MyformId”)。reset();

如果還有其他方法,請告訴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM