javascript - $scope data in array format in angular -


a have test application on angular. try receive data php page in model. response come command echo json_encode($arr); php file , has format [{"id":"1","name":"first","text":"description"}]. receive data in model need use query cause .get give error. query in controller: $scope.item = items.query({id:$routeparams.id}); if want use data in model need specify array item[0].name thats not problem when try save edited data

 $scope.item[0].$save({id:$scope.item[0].id}); 

i have error typeerror: object # has no method 'push'

what doing wrong?

if have resource setup correctly, should able save calling:

$scope.item[0].$save(); 

however, doesn't doing that. when use query, return array. querying single id, should using get method:

$scope.item = items.get({id:$routeparams.id}); ... // modify $scope.item needed ... $scope.item.$save(); 

the simplest way define resource use default actions provided angular:

.factory('items', function($resource) {     return $resource('/angular/angular-seed/app/questions/php/maintext.php'); }); 

as per angular documentation:

the default set contains these actions: { 'get':    {method:'get'},   'save':   {method:'post'},   'query':  {method:'get', isarray:true},   'remove': {method:'delete'},   'delete': {method:'delete'} }; 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -