file ng-chanage失效
Angular对应 onchange
事件的指令是 ng-chanage
,但是在input[type = file]
时 ng-change
是无效的。
原因: ng-change
要与 ng-model
一起使用,但是对于file来讲, ng-model
无法取到文件对象 。
解决方案: <input type="file" onchange="angular.element(this).scope().uploadImage(this.files)">
在controller里面定义函数:
$scope.uploadImage = function(files) {
// 上传代码
}
清空file上传文件名
虽然 input[type = file]
的value属性不能获取文件对象,但是在清空选择是可以设置其value值为空来实现。
angular.element("input[type = file]")[0].value = ""