参考问题File pick with Angular JS,在加载文件阅读器时,我想修改父范围的属性。考虑
$scope.fileLoaded = false; //initially
$scope.file_changed = function(element, $scope) {
$scope.$apply(function(scope) {
var photofile = element.files[0];
var reader = new FileReader();
reader.onload = function(e) {
$scope.fileLoaded = true; // I intend to do!
...
};
reader.readAsDataURL(photofile);
});
});
我如何为 HTML 实现这一点:
<input ng-model="photo"
onchange="angular.element(this).scope().file_changed(this)"
type="file" accept="image/*" />
每次都失败,并出现错误无法设置未定义的属性“fileLoaded”。