我遇到了使用複選框的問題,像ng-repeat中的單選按鈕。在選擇和取消選擇框中,一次只選擇一個框。它正在工作沒有Ng重複。但我想在ng-repeat中使用它。如何使複選框的行爲像ng-repeat中的單選按鈕一樣?
這裏是我的HTML文件:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="[email protected]" src="http://code.angularjs.org/1.1.5/angular.min.js" data-semver="1.1.5"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<h1> WithOut ng-repeat </h1>
<input type="checkbox" ng-checked="model1=='11'" ng-click="model1='11'"> a
<br/>
<input type="checkbox" ng-checked="model1=='12'" ng-click="model1='12'"> b
<br/>
<input type="checkbox" ng-checked="model1=='13'" ng-click="model1='13'"> c
<br>
Model = {{model1}}
<h1> With ng-repeat </h1>
<div data-ng-repeat="p in pp.rate">
<input type="checkbox" ng-checked="model=='{{p.price}}'"
ng-click="model='{{p.price}}'">
Model = {{model}}
</div>
</body>
</html>
這裏是我的控制器:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.pp = {
rate: [ {price: '11'},
{price: '12'},
{price: '13'}
]
};
});
這裏是我的Plunker鏈接 http://plnkr.co/edit/BUHPNjTGaIsG33hsSWeC?p=preview
請給我一個解決方案在此先感謝。
爲什麼不只是使用單選按鈕。這是他們的目的。 – Paddy 2014-10-20 08:36:12
因爲我的要求不是單選按鈕,所以我使用複選框。 – Abhishek 2014-10-20 08:39:23
會悄悄地暗示您的要求可能會從調整中受益。設計師似乎很少知道單選按鈕和複選框之間的區別。 – Paddy 2014-10-20 09:04:40