1
Well, I have a feature on my system that has a great interaction with the end user, I soon chose to employ the Angular.js.
My goal is popular a array dynamically and when user der Ubmit I send such data via $http post.() for a action on my server that will "parse" such array for my object (reponsability linked to Jackson).
But the problem is I don’t know how to do this in the right way, because I have 2 modals on my screen on which every time I press "Add" a list will be dynamically populated on the screen and such data will be included in this tree.
Below I have the tree of my object in which I want to add the data via angular.
customerData = {
"idCustomer":null,
"tenantId":null,
"birthDate":$scope.birthDate,
"email":$scope.email,
"firstName":$scope.firstName,
"gender":$scope.gender,
"lastName":$scope.lastName,
"document":{
"id":null,
"tenantId":null,
"rg":$scope.customerRg,
"cpf":$scope.customerCpf
},
"customerPhone":{
"id":null,
"tenantId":null,
"celPhone":$scope.customerCelPhone,
"homePhone":$scope.customerHomePhone,
"workPhone":$scope.customerWorkPhone
},
"passenger":null,
"customerAddress":{
"id":null,
"tenantId":null,
"cep":$scope.customerAddressCep,
"complement":$scope.customerAddressComplement,
"number":$scope.customerAddressNumber,
"quarter":$scope.customerAddressQuarter,
"street":$scope.customerAddressStreet,
"city":$scope.customerAddressCity,
"state":$scope.customerAddressState,
"country":null
},
"observations":$scope.observations,
"site":false,
"customerService":{
"id":null,
"tenantId":null,
"date": new Date.now(),
"averageBudget":null,
"situation":true,
"serviceItem":[{
}],
"history":[{
"id":null,
"tenantId":null,
"register": "Primeiro Atendimento",
}],
"serviceObservations": "Xpto"
}
};
For example I have a controller to add to serviceItem data in list form:
app.controller('RequestedDestinationModalController', ['$scope', function($scope) {
$scope.addReqDestiantion = function(){
this.customerData.customerService.serviceItem.push({
"id":null,
"destination":$scope.destinationModalCtrl.destination,
"customerService":null,
"tenantId":null,
"valueNegotiated":$scope.destinationModalCtrl.valueNegotiated,
"saleType":$scope.destinationModalCtrl.saleType,
"departureDate":$scope.destinationModalCtrl.departureDate,
"arrivalDate":$scope.destinationModalCtrl.arrivalDate,
"seeIn":$scope.destinationModalCtrl.seeIn,
"requestedDestination":$scope.destinationModalCtrl.requestedDestination,
"negociationObservations":$scope.destinationModalCtrl.negociationObservations
});
};
}]);
But in case I needed to leave mine array which contains the keys of the objects stored somewhere to respectively manipulate it. Here’s the question, how to manipulate the array via multiple *controllers?
You can use a service to store the value to be shared between different controllers. The answer accepts this question and covers the same scope: http://answall.com/questions/64612/angular-usar-mesmo-scope-entre-controles/64615#64615
– OnoSendai