I have a model that looks like this:
var mymodel = {
name: {
en: 'Ten',
es: 'Diez',
fr: 'Dix'
}
};
And a view that looks like:
<section ng-controller="MyController" ng-init="findOne()">
<form ng-submit="update()">
<div ng-repeat="(language, string) in mymodel.name">
<label>Name ({{language | uppercase}}):</label>
<input type="text" ng-model="mymodel.name[language]">
</div>
<input type="submit" value="Update">
<pre>{{mymodel}}</pre>
</form>
</section>
When I modify the value of the textboxes, the object inside pre also changes as expected.
However, when I submit the form, the controller sends the initial values to the backend, instead of the modified ones.
The client controller looks like this:
angular.module('mymodule').controller('MyController', [..., function(...){
...
$scope.update = function() {
var mymodel = $scope.mymodel;
console.log(mymodel.name);
console.log(mymodel);
mymodel.$update(function() {
...
//Does not work as expected. Sends initial data instead of updates.
});
};
...
$scope.findOne = function() {
$scope.mymodel = MyFactory.get({
id: $stateParams.id
});
};
...
}]);
For examlpe, if I type in the following strings: "Fifty", "Cincuenta", "Cinquante", and click "Update", the first console.log(mymodel.name) outputs the new values:
Object {
es: "Fifty",
en: "Cincuenta",
fr: "Cinquante"
}
But the second console.log(mymodel) outputs the initial values instead:
Resource {
$promise: Object
$resolved: true
...
name: Object
en: "Ten",
es: "Diez",
fr: "Dix"
...
}
The result is that the entry does not get updated in the backend.
EDIT
Thank you very much for your answers, I have found the error. The problem was somehow created by a plugin for interationalization in Mongoose ODM. When extending the properties of the response using lowdash, something (I have not found what exactly is yet) prevented the document from being updated, and returned the original values.
Im sorry, this had nothing to do with Angular, I was looking in the wrong place.
ng-repeat="(language, string) in mymodel"should beng-repeat="(language, string) in mymodel.name".