2016-12-09 4 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

uは、ボタンのクリックですべてのチェックボックスをチェックしますか?あなたの目的は何ですか? –

答えて

0

すべてが同じモデルを参照するので、あなたはそのようなボックスにチェックを受けることができない、

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

DEMO

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

助けてくれてありがとう! :)あなたに良い一日。 –

関連する問題