0

带有输入类型复选框的 Angular 表创建代码。

angular.module("tableApp",[]).controller('tableAppCtrl', ['$scope',
  function($scope) {
    $scope.titleString="Table Demo";
    $scope.prodDataTable = [{
      "productType": "A",
      "productName": "Aaaaaa"
    }, {
      "productType": "B",
      "productName": "Bbbbbb"
    }, {
      "productType": "C",
      "productName": "Cccccc"
    }];
  }
]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div  ng-app="tableApp" ng-controller="tableAppCtrl">
  <h3>{{titleString}}</h3>
<table>
  <tr>
    <th><input type="button" value="checkALL"></th>
    <th>Product Type</th>
 <th>Product Name</th>

  </tr>

  <tr ng-repeat="d in prodDataTable">
    <td><input type="checkbox"></td>
    <td>{{d.productType}}</td> 
    <td>{{d.productName}}</td>
  </tr>


</table>
  </div>

我一直在使用角度表,我必须在其中包含一个选择模型。

请建议将其与表格一起使用的方法或链接。

4

2 回答 2

1

使用它,但您需要处理重复的价值创造 -

<div  ng-app="tableApp" ng-controller="tableAppCtrl">
<h3>{{titleString}}</h3>
<table>
  <tr>
    <th><input type="button" value="{{(selectAllval==true) ? 'UncheckALL' : 'checkALL'}}" ng-click="selectAll(selectAllval)"></th>
    <th>Product Type</th>
 <th>Product Name</th>

  </tr>

  <tr ng-repeat="d in prodDataTable">
    <td><input type="checkbox" ng-checked="selectAllval" ng-click="setProductType(d.productType)"></td>
    <td>{{d.productType}}</td> 
    <td>{{d.productName}}</td>
  </tr>


</table>

{{setProductTypes}}

angular.module("tableApp",[]).controller('tableAppCtrl', ['$scope', function($scope) { 
    $scope.titleString="Table Demo"; 
    $scope.selectAllval= false; 
    $scope.setProductTypes= []; 
    $scope.selectAll= function(val){ 
        if(val==false){ 
            $scope.selectAllval= true; 
        } else{ 
            $scope.selectAllval= false; 
        } 
    }; 
    $scope.setProductType= function(type){ 
        $scope.setProductTypes.push(type); 
    }; 
    $scope.prodDataTable = [{ "productType": "A", "productName": "Aaaaaa" }, { "productType": "B", "productName": "Bbbbbb" }, { "productType": "C", "productName": "Cccccc" }]; } ]);
于 2015-12-05T09:47:44.767 回答
0

试试下面的代码 -

angular.module("tableApp",[]).controller('tableAppCtrl', ['$scope',
 function($scope) {
  $scope.titleString="Table Demo";
  $scope.selectAllval= false;
  $scope.selectAll= function(val){
	if(val==false){
		$scope.selectAllval= true;
	} else{
		$scope.selectAllval= false;
	}
  };
  $scope.prodDataTable = [{
  "productType": "A",
  "productName": "Aaaaaa"
  }, {
  "productType": "B",
  "productName": "Bbbbbb"
  }, {
  "productType": "C",
  "productName": "Cccccc"
  }];
 }
]);
  

  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    <div  ng-app="tableApp" ng-controller="tableAppCtrl">
  <h3>{{titleString}}</h3>
	<table>
	  <tr>
	    <th><input type="button" value="{{(selectAllval==true) ? 'UncheckALL' : 'checkALL'}}" ng-click="selectAll(selectAllval)"></th>
	    <th>Product Type</th>
	 <th>Product Name</th>

	  </tr>

	  <tr ng-repeat="d in prodDataTable">
	    <td><input type="checkbox" ng-checked="selectAllval" ></td>
	    <td>{{d.productType}}</td> 
	    <td>{{d.productName}}</td>
	  </tr>


	</table>
  </div>

于 2015-12-05T08:53:52.993 回答