2016-07-15 6 views
0

テキストボックスにデータを挿入してボタンをクリックすると、データが特定のテーブル列に挿入され、データを追加し続けると行が増加し続ける入力されたデータと比較します。コード:クリック時にデータを追加する

var parking = angular.module("parking", []); 
parking.controller("parkingCtrl", function($scope){ 
$scope.carnamebind=''; 
$scope.car=[]; 
$scope.bindcarName = function(){ 
var ee=$scope.car; 

ee.push($scope.carname); 
$scope.carnamebind=ee; 
} 
}) 

HTML:

<body ng-controller="parkingCtrl"> 
<h3 ng-model="appTitle"></h3> 


<table> 
<tr> 
<td>Car name</td> 
<td>Car model</td> 
</tr> 

<tr> 
<td>{{carnamebind}}</td> 
<td></td> 
</tr> 

<tr> 
<td ><input type="text" ng-model="carname"/><input type="button" ng-click="bindcarName()"/></td> 
<td></td> 
</tr> 

</table> 


</body> 

2の問題が来ている:

1)すべてのデータが挿入されている)同じカラム

2に挿入されたアレイにデータをプッシュ配列の形で、["sd","sdasd"]

ありがとう

答えて

0

var app = angular.module("myApp", []); 
 
app.controller("myCtrl", function($scope) { 
 
    $scope.carnamebind= [ 
 
    "Alfreds Futterkiste", 
 
    "Berglunds snabbköp", 
 
    "Centro comercial Moctezuma", 
 
    "Ernst Handel", 
 
    ]; 
 
$scope.bindcarName = function(ee){ 
 

 
$scope.carnamebind.push(ee); 
 

 

 
} 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<!DOCTYPE html> 
 
<html> 
 

 
<body ng-app="myApp"> 
 

 
<table ng-controller="myCtrl" border="1"> 
 
<tr> 
 
<td>Car name</td> 
 
<td>Car model</td> 
 
</tr> 
 
<tr ng-repeat="x in carnamebind"> 
 

 
    <td>{{x}}</td> 
 
    <td></td> 
 
</tr> 
 
<tr> 
 
<td ><input type="text" ng-model="carname"/></td> 
 
<td><input type="submit" ng-click="bindcarName(carname)"/></td> 
 
</tr> 
 
</table> 
 

 

 

 
</body> 
 
</html>

関連する問題