2016-02-08 50 views
0

我正在拿起控制器文件中的複選框數據,但它沒有正確呈現。以下是我的html:checkBox ng-從控制器數據重複不呈現:AngularJs

HTML:

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
</head> 
<body ng-app="myApp" ng-controller="myCtrl"> 
<table> 
    <tr ng-repeat="x in People"> 
     <input type="checkbox" id="{{x.id}}" >{{x.name}}<br/> 
    </tr> 
</table> 
<button>Click</button> 
<script> 
//Module Declaration 
var app = angular.module('myApp',[]); 
//Controller Declaration 
app.controller('myCtrl',function($scope){ 
    $scope.People = [ 
     {name:"Peter",id:"201"}, 
     {name:"Lina",id:"202"}, 
     {name:"Roger",id:"203"} 
    ]; 
}); 
</script> 
</body> 
</html> 

後市展望:以名字輸入複選框

3行adjescent他們

結果:

enter image description here

沒有JS錯誤。有人能幫我解決這個問題嗎?

回答

5

只需添加一個 「TD」 標籤:JSFIDDLE

<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
</head> 
<body ng-app="myApp" ng-controller="myCtrl"> 
<table> 
    <tr ng-repeat="x in People"> 
     <td> 
     <input type="checkbox" id="{{x.id}}" >{{x.name}}<br/> 
     </td> 
    </tr> 
</table> 
<button>Click</button> 
<script> 
//Module Declaration 
var app = angular.module('myApp',[]); 
//Controller Declaration 
app.controller('myCtrl',function($scope){ 
    $scope.People = [ 
     {name:"Peter",id:"201"}, 
     {name:"Lina",id:"202"}, 
     {name:"Roger",id:"203"} 
    ]; 
}); 
</script> 
</body> 
</html>