私はこの問題に瀕しています。アップデートイメージボタンをクリックしようとすると次のようなことが起こります。私のconsole.logにもかかわらず最初の試行でイメージアップデートを実行できないので、正しい値が返されます。何が起こるのは、私がバックエンドにリクエストをするときに、更新ボタンを初めてロードすると、以前にあったイメージのBLOBが返され、また、再試行すると、私が実行しようとしたイメージのBLOBが返されます。前の瞬間と挿入DBに。要するに、彼はいつも遅れた要求をしています。私は既に$スコープを追加しようとしました。 $ Apply()とそれは動作しませんでした。要するにReader.onloadイメージファイルをblob anglejsにアップロードする
First update the blob of the previous image
Second update the blob correct of the image
私は二度、私が欲しいものにイメージを変えることができるように更新を行う必要があります。
コード:
function uploadFile(){
var file = $scope.profilePic;
var blob = new Blob([file], {
"type": "text/html"
});
var reader = new FileReader();
reader.onload = function(e) {
$scope.text = e.target.result.split(',')[1];
$scope.loadedUser.profilePic = $scope.text;
}
reader.readAsDataURL(blob);
};
HTML:
<div layout-gt-sm="row" style="margin-bottom: 20px;">
<input type="file" name="profilePic" fileread="profilePic">
</div>
APP:
app.directive("fileread", [function() {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
scope.$apply(function() {
scope.fileread = changeEvent.target.files[0];
// or all selected files:
// scope.fileread = changeEvent.target.files;
});
});
}
}
}]);