'How to know if my radio button is checked? AngularJS

guys I did a code for knowing if my checkbox is checked and works fine:

HTML:

<div ng-app>
    <div ng-controller="UserController">
        <table id="tblUsers" class="Table">
            <thead>
                <tr>
                    <th></th>
                    <th>Name</th>
                    <th>Last Name</th>
                    <th>Phone</th>
                </tr>
                <tr ng-repeat="user in users">

                    <td><input type="checkbox" ng-model="user.checked"/></td>
                    <td>{{user.name}}</td>
                    <td>{{user.lastName}}</td>
                    <td>{{user.phone}}</td>
                </tr>
        </table>

     </div>   
</div>

This is the Angularjs code:

function UserController($scope) {
    $scope.users = [
        { checked: false, name: 'Jorge', lastName: 'Martinez', phone: 012345 },
        { checked: false, name: 'Juan', lastName: 'Perez', phone: 78964 }
    ];

    $scope.updateUser = function () {
        angular.forEach($scope.users, function (user) {
            if (user.checked) {
                user.name = $scope.nameUpdate;
                user.lastName = $scope.lastNameUpdate;
                user.phone = $scope.phoneUpdate;
            }
        });
    };
}

The problem is when I change the checkbox for a radio button:

<td><input type="radio" ng-model="user.checked"/></td>

When I do this, this value "if(user.checked)" appears as "undefined". Some one that knows how to fix this or how to know if the radio button is checked or not in the AngularJS controller.



Solution 1:[1]

see https://docs.angularjs.org/api/ng/input/input%5Bradio%5D

you'll want to have multiple radio buttons, each with it's own value to set some property to (although this is weird for a yes no you are better off with a checkbox, but if you had multiple values this is how radio buttons work)

<input type="radio" ng-model="user.checked" ng-value="true" />Yes
<input type="radio" ng-model="user.checked" ng-value="false" />No

when you have just one radio button, if it is not checked by default or you have no ng-value it will be undefined, but also having only one radio button, you could never unselect it.

Solution 2:[2]

You need to give the radio button a value.

<td><input type="radio" ng-model="user.checked" value="true"/></td>
<td><input type="radio" ng-model="user.checked" value="false"/></td>

Working Fiddle

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dumdum
Solution 2