我尝试在选择文件后将范围值更改为文件路径。
这是html文件
<input type="file" name="file" onchange="angular.element(this).scope().showFilePath(this)">
<div>{{filename}}</div>
在 Controller 中
angular.module('app')
.controller('UploadFile', function($scope){
$scope.filename = 'please upload a file'
$scope.showFilePath = function(file){
console.log(file.value)
$scope.filename = file.value
console.log($scope.filename)
}
})
哪里console.log($scope.filename)
显示“C:\fakepath\1m.jpg”,但在网页中仍然显示“请上传文件”
我该如何处理这个问题?
谢谢
最佳答案
我希望你已经尝试过这个
$scope.showFilePath = function(file) {
console.log(file.value)
$scope.filename = file.value
$timeout(function() {
$scope.$apply();
}, 1000)
}
关于javascript - 选择文件后范围变量未更改其值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47951677/