2017-03-16 79 views
0

我總共有10個按鈕,我怎麼能移動到一個新行,每2個按鈕:更改爲新行每2個按鈕

HTML

<div ng-controller="SimpleArrayCtrl"> 
    <div class="form-group"> 
     <label ng-repeat="fruitName in fruits" class="checkbox-inline"> 
     <input type="checkbox" 
       name="selectedFruits[]" 
       value = {{fruitName}}"   
       ng-checked="selection.indexOf(fruitName) > -1" 
       ng-click="toggleSelection(fruitName)" 
      > {{fruitName}} 
     </label> 
    </div> 
</div> 

JS

(function (app) { 
'use strict'; 

app.controller('SimpleArrayCtrl', 
       ['$scope', function SimpleArrayCtrl($scope) { 
// fruits 
$scope.fruits = ['apple', 'banana', 'c', 'd','e','f','g','h','i','j']; 

// selected fruits 
$scope.selection = []; 

// toggle selection for a given fruit by name 
    $scope.toggleSelection = function toggleSelection(fruitName) { 
     var idx = $scope.selection.indexOf(fruitName); 

     // is currently selected 
     if (idx > -1) { 
     $scope.selection.splice(idx, 1); 
     } 
     // is newly selected 
     else { 
     $scope.selection.push(fruitName); 
     } 
    }; 
    }]); 
})(angular.module('app', [])); 

https://jsbin.com/goqekewalu/edit?html,js,output

+0

你或許可以這樣做只是使用CSS,設置樣式爲'複選框,inline'到是50%寬? – haxxxton

回答

0

你可以用css來做到這一點,無論是內聯塊,還是花車。對於花車做這方面的例子可以添加這種風格你的CSS文件:

.form-group label.checkbox-inline { 
    padding-left: 40px; 
    margin-left: 0; 
    float: left; 
    width: 50%; 
} 

現場演示:https://jsbin.com/qawoqagebu/1/edit?html,css,js,output