Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm getting this weird url from Angular's $resource:

DELETE /dashboard/api/1.0/journalEntry?0=5&1=4&10=9&11=3&12=2&13=f&14=7&15=f&16=1&17=6&18=1&19=4&2=0&20=9&21=2&22=a&23=a&3=7&4=9&5=6&6=e&7=e&8=5&9=f

When what I'm really expecting is this:

DELETE /dashboard/api/1.0/journalEntry/540796ee5f932f7f161492aa

I've tried that URL and the server side appears to be working. It's a problem with the Angular Router Service.

Here's where I define the service:

'use strict';
angular.module('mean.dashboard')
.factory('JournalEntry', ['$resource',
  function($resource){
    return $resource('dashboard/api/1.0/journalEntry/:journalEntryId/', {
      journalEntryId: '@_id'
    }, {
      update: {
        method: 'PUT'
      }
    });
  }
]);

And here's the controller where I call Resource:

$scope.editDeleteRow = function(item) {
  console.log(item._id);
  JournalEntry.remove(item._id).$promise.then(
    function(response) {
      $scope.addAlert('edit', 'Deleted', 'success');
      //TODO remove item from client list
      $scope.groupJournalEntries();
    },
    function(err) {
      $scope.addAlert('add', 'Error ' + err.statusText, 'danger');
      console.log(err);
    }
  );
};

What I miss?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I'm in a hurry so I didn't figure this one out all the way. It had something to do with @ not working the way I expected. I got it to work defining the service like this:

.factory('JournalEntry', ['$resource',
  function($resource){
    return $resource('dashboard/api/1.0/journalEntry/:journalEntryId', {
    }, {
      update: {
        method: 'PUT'
      }
    });
  }
]);

And calling it like this:

  JournalEntry.remove({journalEntryId: item._id}).$promise.then(
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.