Ben David Ben David - 1 year ago 70
AngularJS Question

can't change radio button value by code - angularjs

I am trying to create a radio button, that when the user click "active" - an alert will appear. If he clicked cancel, stay (or go back) to the old value.
problem is, the what happens is that both of the radio buttons are "unchecked". and thats obviously not the wanted behaviour.

I've attached a code example.
code example

thanks in advance,

Answer Source

Add timeout before setting the value to false.

var app = angular.module('app', []);

app.controller('firstCtrl', function($scope,$timeout){

 $scope.value = {
   text : false
  $scope.checkRadioButton = function() {
    if ($scope.value.text === true) {
      if (!window.confirm("Are you sure?")) {
          $scope.value.text =  false;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download