Hello,
I have a angular app that lets users update items against a REST NoSQL
backend (MongoLab) I wonder how I can update an item without having to
enumerate all keys - value pairs in a $http.put() call?
My code:
View:
<tr ng-repeat-start="item in items | orderByPriority">
<td><input type="text" ng-model="item.startDate"></td>
<td><input type="text" ng-model="item.endDate"></td>
[...more fields...]
<td><span ng-click="updateItem(item)"> </span></td>
itemController:
// update an item
$scope.updateItem = function(item){
dataService.updateItem(item)
.success(...)
.error(...)
dataservice
service.updateItem = function(item){
return $http({
method: 'PUT',
url: itemsRef + '/' + item.id + '?apiKey=' + apiKey,
data: JSON.stringify({"$set" : {
"startDate":item.startDate,
"endDate":item.endDate,
"name":item.name,
"notes":item.notes,
"fileSrc":item.fileSrc,
"fileName":item.fileName,
"fileType":item.fileType,
"fileSize":item.fileSize
}}),
contentType: "application/json"
});
};
This works but I prefer not to explicitly enumerate all the fields...so
that when later a field is added I will not have to update this
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.