Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete property from scope variable

I have a scope variable $scope.object = { prop: 12345 } whose properties I delete with setting them to undefined.

<button ng-show="object.prop" ng-click="object.prop = undefined"/>

Is there a possibility to delete a properties from within a template and without an additional function in the controller instead of setting their values to undefined?

like image 579
Sebastian Barth Avatar asked Nov 25 '14 12:11

Sebastian Barth


People also ask

How do I remove a property from an object?

Remove Property from an ObjectThe delete operator deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.

How do you remove one property from an object in TypeScript?

To remove a property from an object in TypeScript, mark the property as optional on the type and use the delete operator. You can only remove properties that have been marked optional from an object.

Which keyword is used for deleting properties on objects?

delete keyword is used to delete properties of an object in javaScript.


1 Answers

use codes below to delete a property from a object

In HTML

<button ng-show="object.prop" ng-click="deleteProperty()" />

In Controller

$scope.deleteProperty = function() {
    delete $scope.object.prop;
}    
like image 87
Kalhan.Toress Avatar answered Sep 20 '22 05:09

Kalhan.Toress