0

I am trying to use loopback angular resource for website part. it seems $save on model gives error Cannot read property 'call' of undefined at Resource.LoopBackResource.resource.$save. i can't seem to find any answers. I am working on angular 1.5.8. any help would be appreciated

code:

   $scope.updateUser = function () {
    $scope.newUser.$save(function (res) {
        logger.log('updated');
    },function (err) {
        logger.log('update failed',err);
        })
    };
Taj Ahmed
  • 895
  • 11
  • 19

1 Answers1

0

is $scope.newUser a valid model object ? If yes then the above code should work. Your valid model object can be obtained by

Member.findById({
  id: your_id
}, function(user) {
  user.attribute = 'new value';
  user.$save();
})

Once the member details are retrieved, store it in newUser .

itssajan
  • 820
  • 8
  • 24
  • it is a valid model object. data and methods as well – Taj Ahmed Jun 10 '17 at 09:13
  • how are you storing your valid object model to newUser ? can i see the code ? – itssajan Jun 10 '17 at 09:14
  • it is coming from users list `User.find(function (users) { $scope.users = users; });` and then i pick one to update – Taj Ahmed Jun 10 '17 at 09:16
  • this is wrong. You can only use `$save()` for one object. Try using `findOne` or `findById`. `$scope.users` is an array, not an object – itssajan Jun 10 '17 at 09:18
  • i do get one by `$scope.newUser = $scope.users[userIdx]` – Taj Ahmed Jun 10 '17 at 09:19
  • I don't think it works that way. By using find you get the whole data objects in array. But if you use `findById` it gives you the one object model as a whole. Or you can try `prototype$updateattributes` – itssajan Jun 10 '17 at 09:23