VSO
VSO

Reputation: 12656

How to Deselect All Radio Inputs?

I am using angular and have a radio input like this (in a form, if it matters):

<input type="radio"
       name="inputName"
       id="someId"
       data-ng-value=true <!-- This select "true" for my ng-model when clicked-->
       ng-model = "nameOfMyVarIn$scope"
       ng-change = "thisRunsWhenSelectionIsmade(true)"
       required></input>

I want to clear this input. Clearing the variable bound to ng-model clears the variable, but not the checkbox. I can't find how to clear the radio button itself in the docs or in random articles - it stays selected. I made a quick copy of the example from the docs and added $scope.clearSelection - the goal is to have this function de-select the selected input. In the real application I have other inputs in the form, so I can't just clear the whole form.

Plnkr

Upvotes: 0

Views: 82

Answers (1)

ThiagoPXP
ThiagoPXP

Reputation: 5462

Using your Plnkr, I've set color to null and it cleared the value. Is this what you want?

$scope.clearSelection = function(){
    $scope.color = null;
}

Here is the updated Plnkr

Upvotes: 1

Related Questions