Here you can remove any property name from the scope object. This method requires the use of the Underscore.js library.
index.html
//Underscore.js must be imported <script src="path/to/underscore/underscore-min.js"></script> //Replace prop with any property name <button ng-click="removeMyProperty(object, 'prop')">Test</button>
controller
$scope.object = {"prop": "test", "anotherProp" : 10}; $scope.removeMyProperty = function(variable, propName){ var keys = _.keys(variable); _.each(keys, function(data){ if(data === propName){ $scope.object = _.omit(variable, propName); } else { console.log("No such property name in array!"); } }); };
This only works when using the Underscore.js library, and therefore, you must add it to your project path and import the underscore.js file into index.html
If you are not familiar with Underscore, go here Underscore.js
source share