M
M
Max Zhukov2017-10-17 12:04:37
Angular
Max Zhukov, 2017-10-17 12:04:37

Why doesn't the value of a variable change in angular?

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];
varfile = 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];
varfile = element.files[0];
if (file){
var reader = new FileReader();
reader.onloadend = function () {
$scope.grandPrize.img = reader.result;
}
reader.readAsDataURL(file);
}
}
});
});
The variable itself is updated when the image is opened, but does not change in the label.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question