I'm using the excellent AngularJS Rails Resources and with one object - which has deep nested objects in turn - when I update some of its properties, the updated property does not show on the template until I reload the page.
Let start from the beginning: here's my object:
var invoice = Invoice.get($stateParams.invoiceId).then(function (result) {
$scope.invoice = result;
});
And here's how I open my modal to edit the values:
$scope.openEdit = function (edit) {
$scope.editModal = $modal.open({
templateUrl: 'editModalContent.html',
controller: 'InvoiceShowController',
size: 'lg'
});
$scope.editModal.result.then(function(select) {
});
};
$scope.cancel = function () {
$scope.$close();
};
$scope.ok = function () {
$scope.invoice.update().then(function (result) {
$scope.cancel();
console.log(result);
});
};
In my view I have the following:
...
<li>{{invoice.trading_details.trading_name}}</li>
<li>{{invoice.trading_details.trading_address_1}}</li>
...
In the modal body I have the following:
...
<div class="form-group">
<label for="exampleInputEmail1">Trading Name</label>
<input ng-model="invoice.trading_details.trading_name" type="text" class="form-control" id="exampleInputEmail1">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Trading Address Line 2</label>
<input ng-model="invoice.trading_details.trading_address_1" type="text" class="form-control" id="exampleInputEmail1">
</div>
...
So when I edit the properties in the modal and console the object, the changes are there. When I save and get the result back, the changes are there, but for whatever reason the view is not updating.
Any ideas?
EDIT: My whole controller
invoiceobjects on two different scopes. Could you try logging out $scope.$id in both view and modal?$scopeto the modal? One thing that beats me is in the Angular Bootstrap example why is there a need for two controllers?