Image
.controller('AdminPrizesCtrl', function ($scope, Prizes) {
console.log('AdminPrizesCtrl');
var prizes = null;
Prizes.getPrizes()
.then(function (response) {
var prizes = response.data;
console.log(prizes);
$scope.prize = prizes.prize;
if ($scope.prize.img==null){
$scope.prize.img='/media/noImg.png';
}
$scope.postPrize = function() {
var fd = new FormData;
fd.append('name', $scope.prize.name);
fd.append('description', $scope.prize.description);
if (typeof $scope.prize.imgFile !== 'undefined') {
fd.append('img', $scope.prize.imgFile);
}
Prizes.postPrize(fd)
.success(function(response) {
console.log(response);
$scope.prize = response.prize;
$scope.grandPrize = response.grandPrize;
})
.error(function(error) {
console.log(error);
});
};
$scope.readPrizeImg = function (element) {
$scope.prize.imgFile = element.files[0];
var file = element.files[0];
if (file){
var reader = new FileReader();
reader.onloadend = function () {
$scope.prize.img = reader.result;
}
reader.readAsDataURL(file);
}
};
$scope.grandPrize = prizes.grandPrize;
if ($scope.grandPrize.img!=null){
$scope.grandPrize.img='/media/noImg.png';
}
$scope.postGrandPrize = function() {
var fd = new FormData;
fd.append('name', $scope.grandPrize.name);
fd.append('description', $scope.grandPrize.description);
if (typeof $scope.grandPrize.imgFile !== 'undefined') {
fd.append('img', $scope.grandPrize.imgFile);
}
Prizes.postGrandPrize(fd)
.success(function(response) {
console.log(response);
$scope.prize = response.prize;
$scope.grandPrize = response.grandPrize;
})
.error(function(error) {
console.log(error);
});
};
$scope.readGrandPrizeImg = function (element) {
$scope.grandPrize.imgFile = element.files[0];
var file = element.files[0];
if (file){
var reader = new FileReader();
reader.onloadend = function () {
$scope.grandPrize.img = reader.result;
}
reader.readAsDataURL(file);
}
}
});
});
Сама переменная обновляется, при открытии картинки, но не изменяется в label.
-
Вопрос задан
-
166 просмотров