我尝试使用单选按钮执行this。我从角度开始,我不能对无线电应用相同的动作。
ChildClass
<!DOCTYPE html>
<html ng-app="angularjs-starter">
感谢您的帮助!
答案 0 :(得分:0)
在你的app.js中,尝试将isChecked添加到你的模块对象然后用它作为module.isChecked in ng-repeat
$scope.modules = [
{ title: 'Module 1', description: 'Description 1', isChecked: false },
{ title: 'Module 2', description: 'Description 2', isChecked: false },
{ title: 'Module 3', description: 'Description 3', isChecked: false }
];
答案 1 :(得分:0)
工作示例 - https://jsfiddle.net/Shital_D/g8ksad4k/1/
<div ng-controller="MainCtrl">
<ul class="module_list" ng-controller="CheckedController">
<li ng-repeat="module in modules">
<div class="span4 module_card" ng-class="{ checked : isChecked == module.title , unChacked: isChecked != module.title}">
<input id="{{module.title}}" type="radio" name="radio" class="custom_checkbox" ng-click="checked(module.title)" ng-value="module.title">
<label class="title" for="{{module.title}}">{{module.title}}</label>
<p>{{module.description}}</p>
<p>{{isChecked}}</p>
<p><a class="btn btn_addlearning" ng-class="getCardButtonClass(module)" ng-click="addToMyLearning(module)">{{createButtonText(module)}}</a>
</p>
</div>
</li>
</ul>
</div>
var app = angular.module('myApp', []);
app.controller('MainCtrl', function ($scope) {
$scope.modules = [{
title: 'Module 1',
description: 'Description 1'
}, {
title: 'Module 2',
description: 'Description 2'
}, {
title: 'Module 3',
description: 'Description 3'
}];
});
app.controller('CheckedController', function ($scope) {
$scope.isChecked = '';
$scope.checked = function(title) {
$scope.isChecked = title;
}
答案 2 :(得分:0)
<div class="form-group">
<label>Type of ad <b class="text-danger">*</b></label><br>
<input type="radio" name="typeofAd" value="sell" ng-model="product.typeofAd"> I want to sell
<input type="radio" name="typeofAd" value="buy" ng-model="product.typeofAd"> I want to buy
</div>
参考链接 https://scotch.io/tutorials/handling-checkboxes-and-radio-buttons-in-angular-forms