i try clone response json, id same..
i want clone item in json facilitate addition of content. problem following same id, answer update , no new item ..
the function:
$scope.cloneitem = function(id) { $scope.itemtoclone = alldb.get({section: section, id: id}, function(){ $scope.itemnew = new alldb({section: section}); $scope.itemnew = angular.copy($scope.itemtoclone); $scope.itemnew.$save(function(){ $mdtoast.show($mdtoast.simple({position: 'top right'}).content('clone criado!')); }); }); } and response:
get http://localhost:5000/posts/25 304 not modified 7ms post http://localhost:5000/25 201 created 2ms json object clone:
{ "id": 25, "title": "willian busca protagonismo igual ao de neymar: \"sempre joguei assim\"", "subtitle": "com 94% de aproveitamento nos passes na estreia da copa américa, jogador tem chamado responsabilidade e dividido missão de criar os lances com o camisa 10", "slug": "brasil-post-1", "published": true, "originaldate": "2015-06-16t03:00:00.000z", "excerpt": "com 94% de aproveitamento nos passes na estreia da copa américa", "$promise": {}, "$resolved": true, "cats": [ 2, 3, 4, 5, 7 ] } resolved, not quite wanted, help!
$scope.cloneitem = function(id) { $scope.getclone = alldb.get({section: section, id: id}, function(response){ console.log(response); $scope.itemnew = new alldb({section: section}); $scope.itemnew.title = response.title; $scope.itemnew.subtitle = response.subtitle; $scope.itemnew.excerpt = response.excerpt; $scope.itemnew.$save(function(){ $mdtoast.show($mdtoast.simple({position: 'top right'}).content('clone criado!')); }); }); }
Comments
Post a Comment