Reputation: 449
i want to send change the value "false" in mentions-->"rcs"--> "visible" into multiple array in json
Im new in angular and i don t know how i can manage that so try that but it s not working. Can you help me ?
in my json array there is an object called "mentions" and in this object an array with an other object called "rcs" (at the end of the file) and there is the line "visible" which is a boolean . I want to change this boolean to "true" because it is currently "false"
Here is my json :
"data": {
"company_name": "Laplagem",
"entrepreneur_firstname": "guillaumO",
"entrepreneur_lastname": "nouveaunomF",
"login": "[email protected]",
"company_address": "120 rue de la pacrette fraiche",
"company_zipcode": "78630",
"company_city": "Pignons sur rue",
"company_country": "France",
"company_phone": "0123435522",
"activity_type": "V",
"declaration_period": "M",
"activity_start": "2016-02-01",
"company_siret": "53106089500020",
"rcs_city": "Paris",
"naf_code": "",
"has_accre": false,
"invoice_header": "Laplagem\nguillaumO nouveaunomF\n120 rue de la pacrette fraiche\n78630 Pignons sur rue\[email protected]\n0123435522",
"invoice_footer": "SIRET : 53106089500020 - RCS : Paris",
"invoice_payment_delay": "60",
"bank_balance": 0,
"mentions": {
"vat": {
"value": "TVA non applicable, art. 293 B du CGI",
"visible": true,
"alwaysVisible": true,
"alterable": false
},
"delay": {
"value": "En cas de retard de paiement, une pénalité de 3 fois le taux d’intérêt légal sera appliquée, à laquelle s’ajoutera une indemnité forfaitaire pour frais de recouvrement de 40€",
"visible": true,
"alwaysVisible": true,
"alterable": true
},
"free": {
"value": "Ma nouvelle mention perso",
"visible": true,
"alwaysVisible": false,
"alterable": true
},
"bank": {
"value": "",
"visible": true,
"alwaysVisible": false,
"alterable": true
},
"cga": {
"value": "Membre d’une association agréée, le règlement des honoraires par chèque est accepté",
"visible": true,
"alwaysVisible": false,
"alterable": true
},
"rcs": {
"value": "Dispensé d’immatriculation au registre du commerce et des sociétés (RCS)",
"visible": false,
"alwaysVisible": false,
"alterable": true
}
}
}.
Here is my controller :
$scope.valuercs = function(){
var mytoken = sessionStorage.getItem('token');
var transform = {"mentions":{"rcs": {"value" : "true"}} };
factovalrcs.send(mytoken, transform).then(function(conf){
console.log(conf);
});
}
Here my service :
.factory('factovalrcs', ['$http','$q', function ($http,$q){
var newdata = {};
newdata.send = function(mytoken, transform){
var deferred = $q.defer();
$http({
method: 'POST',
url: "http://api.tiime-ae.fr/0.1/request/settings-update.php",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {token: mytoken, transform}
})
.success(function(conf){
deferred.resolve(conf);
// var promise = deferred.promise;
// promise.then(function(result){
// var mydata = result["data"];
// console.log(mydata);
// }
//);
});
return deferred.promise;
};
return newdata;
}])
Upvotes: 0
Views: 132
Reputation: 5020
You can't simply assign to $scope.valuercs
, because your AJAX call is asynchronous. You need to toggle the visible
bit in the success function and also assign the result to $scope.valuercs
:
var mytoken = sessionStorage.getItem('token');
var transform = {"mentions":{"rcs": {"value" : "true"}} };
factovalrcs.send(mytoken, transform).then(function(conf){
console.log(conf);
conf.data.mentions.rcs.visible = true;
console.log(conf);
$scope.valuercs = conf;
});
Upvotes: 1