【发布时间】:2018-01-28 10:30:22
【问题描述】:
我必须使用 Firebase 在 AnguarJS 中上传图像,但问题是图像已正确上传,并且我必须将 imageURL 存储到 localStorage 但刷新页面图像后我不明白什么问题
$scope.backgroundImageURL = [];
$scope.currentUserObject = {};
$scope.uploadBackgroundImage = function(event) {
//Get the userDetail of the current logged in user
$scope.currentUserObject = localStorage.getItem('userName');
//Get the value from the input field and assign into the fireabse node
var userProductImg = $("#getImageAttribute")[0].files[0];
var PRODUCT_STORAGE_REF = firebase.storage().ref('user/image');
//get the date as well as put the imageURL from node
var rn = new Date().getTime().toString();
var task = PRODUCT_STORAGE_REF.child("loggedInUserObject").child($scope.currentUserObject).child(rn).put(userProductImg).then(function(snapshot) {
$timeout(function(){
$scope.backgroundImageURL.push(snapshot.downloadURL);
localStorage.setItem('userImageURL', $scope.backgroundImageURL);
}, 50);
})
}
<input type="file" id="getImageAttribute" ng-click="$event = $event" ng- model="display" multiple onchange="angular.element(this).scope().uploadBackgroundImage(event)"
/>
<span ng-repeat="imgURL in backgroundImageURL">
<img src="{{imgURL}}">
</span>
?
【问题讨论】:
标签: javascript angularjs firebase