Delete property from scope variable

Sebastian Barth picture Sebastian Barth · Nov 25, 2014 · Viewed 27.5k times · Source

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?

Answer

Kalhan.Toress picture Kalhan.Toress · Nov 25, 2014

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;
}