【发布时间】:2014-11-05 13:45:06
【问题描述】:
伙计们,我做了一个代码来了解我的复选框是否被选中并且工作正常:
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>
这是 Angularjs 代码:
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;
}
});
};
}
问题是当我更改单选按钮的复选框时:
<td><input type="radio" ng-model="user.checked"/></td>
当我这样做时,这个值“if(user.checked)”显示为“未定义”。 有人知道如何解决此问题或如何知道 AngularJS 控制器中是否选中了单选按钮。
【问题讨论】:
标签: html angularjs checkbox radio-button