2016-12-09 1 views
0

즉 확인란이있는 방법입니다. 예를 들어 버튼을 클릭 할 때와 같아야하므로 둘 이상이어야한다는 것을 알고 있어야합니다. 그들 중 하나. 따라서 총 가치는 더 커야합니다.체크 박스가 두 개 이상 선택되어 있는지 확인합니다.

내 console.log()에 오류나 성공 메시지가 표시되지 않습니다.

<input type="checkbox" 
     ng-checked="ItemSelected" 
     name="SelectedTypes" 
     value="2" /> 
<input type="checkbox" 
     ng-checked="ItemSelected" 
     name="SelectedTypes" 
     value="3" /> 
<input type="checkbox" 
     ng-checked="ItemSelected" 
     name="SelectedTypes" 
     value="4" /> 

<input type="button" class="btn btn-success" value="Næste" ng-click="UppersViewClick()" /> 

CreateUserInfo.js - 파일

$scope.UppersViewClick = function() 
{ 
    if ($scope.ItemSelected !== undefined) 
    { 
     if ($scope.ItemSelected.length > 1) { 
      $scope.UppersViewInfo = false; 
      $scope.PantsViewInfo = true; 
      console.log("succes") 
     } 
     else 
     { 
      console.log("error"); 
     } 
    } 
} 

그래서 내가 확인해야한다는 것입니다 목적 나 그 이상의 하나 또는 모두 중 단지 값.

+0

이 유 클릭 모든 체크 박스 버튼을 확인 하시겠습니까 DEMO? 또는 당신의 목적은 무엇입니까? –

답변

0

모두 같은 모델을 의미하기 때문에 당신은 같은 상자를 확인받을 수 없습니다

$scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ]; 

var app = angular.module('plunker', []); 
 

 
app.controller('MyCtrl', function($scope) { 
 
    $scope.records = [ { "Id": 1 }, { "Id": 2 }, { "Id": 3 } ]; 
 
    $scope.selected = {}; 
 
    $scope.ShowSelected = function() { 
 
     $scope.records = $.grep($scope.records, function(record) { 
 
     return $scope.selected[ record.Id ]; 
 
     }); 
 
    };  
 
});
<!doctype html> 
 
<html ng-app="plunker" > 
 
<head> 
 
    <meta charset="utf-8"> 
 
    <title>AngularJS Plunker</title> 
 
    <link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> 
 
    <link rel="stylesheet" href="style.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script> 
 
    <script src="https://raw.github.com/twitter/bootstrap/master/docs/assets/js/bootstrap.js"></script> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script> 
 
    <script src="https://raw.github.com/angular-ui/angular-ui/master/build/angular-ui.js"></script> 
 
    <script src="app.js"></script> 
 
</head> 
 
<body> 
 
<div data-ng-controller="MyCtrl"> 
 
    <ul> 
 
     <li data-ng-repeat="record in records"> 
 
      <input type="checkbox" ng-model="selected[record.Id]"> {{record.Id}} 
 
     </li> 
 
    </ul> 
 
    <a href="javascript:;" data-ng-click="ShowSelected()">Show Selected</a> 
 
</div> 
 
\t </body> 
 
</html>

+0

도움에 감사드립니다! :) u에 좋은 하루., –

관련 문제