1

Removing a object property using delete doesn't seem to work with angular. The object remains unchanged. The weird thing is that I can add properties to the object just fine.

Could it be because the object is exposed in $scope ? But how can I remove properties from it then?

This is my code

const {remote} = require('electron');

angular.module('myapp', []).service('db', function(){

  var data = remote.getGlobal('data');

  return {

    removeItem: function(item){
      console.log(delete data[item]); -> returns false!!
    }


  }

});

I'm calling the method from a controller:

$scope.removeAction = function(item){
  db.removeItem(item);
};

removeAction is called on ng-click of a button

1 Answer 1

2

Currently you're just modifying data object in db service. I don't see any variable references directly bounded to your $scope variable. Hence you have to fetch data once again from the db(service) as you want to see the changes on $scope variable.

$scope.removeAction = function(item){
  //may be you have to update data variable once again
  //data = remote.getGlobal('data'); //then removeItem
  db.removeItem(item);
  //retrieve latest list from `db` service once again.
  $scope.data = db.getData(); //assumed data is collection retrieved from db.
};
Sign up to request clarification or add additional context in comments.

4 Comments

but it doesn't remove it in the db service either. I console logged it just after delete and it stays the same, and delete returns false
Are you sure you data object is updated when you trying to delete item??
its not updated, thats what im trying to say. it doesnt delete the property
nvm i found out why, its because of the electron global thing. if I replace that with some example object it works..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.