2016-01-21 51 views
0

我想讓複選框像單選按鈕一樣工作。 當一個複選框被選中時,另一個複選框應該會自動取消選中。我想使複選框像angularjs單選按鈕一樣行動

任何人都可以告訴我該怎麼做。

Example

<label ng-repeat="role in roles"> 
    <input id="{{role.text}}" type="checkbox" onbeforesave="validateRequired($data)" 
      ng-click="$last&&mytest(checked)" ng-disabled="user.text" 
      checklist-model="user.roles" checklist-value="role.text" 
      ng-init="user.roles=false"/> 
       {{role.text}} &nbsp;&nbsp; 
</label> 
+0

只是使用單選按鈕無法使用? – dfsq

+0

沒有問題:( – User123

+0

什麼是用戶案例更改複選框單選按鈕 –

回答

1
// HTML in INPUT 
ng-true-value="{{role.id}}" ng-false-value="" ng-model="result.id" 
// Controller 
$scope.result = {}; 

你可以檢查$指數一樣,

 $scope.check = function (index) { 
       $scope.type = index;   
      } 
    $scope.type === $scope.result.id 
>>>>> true 

其工作:)

+0

感謝回覆@ Mike86在html行iam使用checklist-model =「user.roles」不是ng-model =「」。它與清單模型一起工作? – User123

+0

它沒有差異jsut添加我的代碼輸入和控制器,並嘗試它的工作:)請接受回答有用的兄弟 – SuperComupter

+0

它現在工作@ Mike86,你能請把它展示在我有連接。我敢肯定會接受你的答案兄弟。 – User123