使用AngularJS的第一周,我使用了来自https://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs
的文件上传指令代码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]);
});
});
}
};
}]);
在阅读内容时效果很好 - 用户选择文件,我在JS中读取它,然后在将其发送到服务器之后我想清除它(通过设置null
)。这就是问题 - 它不起作用,<input>
中的文件名不会改变。
我应该如何修改它获得双向指令?