kitimenpolku
kitimenpolku

Reputation: 2604

Restangular - Removing property from element

Im trying to remove a property element before doing the submission of that element.

$scope.changeTitle = function(song, title){
    song.title = title;
    delete song.label;

    song.put();
}

When doing so it seems that the property "label" is removed. When I do the PUT operation the object actually has the property label.

// This is the object I'm sending (checked from the chrome dev tool - network)
{
  artist: "XXXXX"
  title: 'XX'
  label: []
}

Is there any way to remove a property from an element?

Upvotes: 0

Views: 740

Answers (2)

Emil Stolarsky
Emil Stolarsky

Reputation: 108

If you inspect the object's put method in Developer console, you'll find that the referenced object is actually your original object (even after changes). In order fix the reference, use Restangular.copy() before you manipulate the object.

Earlier when you wrote something along the lines of:

$scope.song = restangular.one(song, 1).get().$object;

You should instead write:

$scope.song = restangular.copy(restangular.one(song, 1).get().$object);

To see the related issue, checkout: https://github.com/mgonto/restangular/issues/55

Upvotes: 3

akn
akn

Reputation: 3722

You can use underscore's _.omit function (http://underscorejs.org/#omit)

song = _.omit(song,'label');

Upvotes: 0

Related Questions