angular js 實現表單提交時下面的table擷取到表單裡面的資料

來源:互聯網
上載者:User

標籤:blog   module   htm   logs   str   cli   對象   click   ng-model   

angular js 實現表單提交時下面的table擷取到表單裡面的資料
<!DOCTYPE html>
<html >
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script src="../angular-1.5.5/angular.min.js"></script>




</head>
<body ng-app="myApp" ng-controller="ctrl">

<form action="">
<p>姓名 <input type="text" ng-model="name"/></p>
<p>年齡 <input type="text" ng-model="age"/></p>
<p>性別 <input type="text" ng-model="sex"/></p>

</form>
<button type="submit" class="btn btn-info" ng-click="add()">提交</button>

<table class="table table-bordered" >
<thead>
<tr>
<th>姓名</th>
<th>年齡</th>
<th>性別</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="elem in array">
<td>{{elem.name}}</td>
<td>{{elem.age}}</td>
<td>{{elem.sex}}</td>
</tr>
</tbody>
</table>


</body>
<script>

var app= angular.module("myApp",[]);
app.controller("ctrl",function($scope){
$scope.array=new Array(); //建立一個空數組

$scope.add=function(){
$scope.object=new Object(); //建立一個Null 物件用來放資料或者(var object=new Object())
$scope.object.name=$scope.name; /*($scope.object.name)為拓展對象裡面的name屬性*/
$scope.object.age=$scope.age;
$scope.object.sex=$scope.sex;
$scope.array.push($scope.object);/* 把對象裡面的資料添加到數組裡*/
console.log(this);
console.log($scope)
}

})
</script>
</html>

 



angular js 實現表單提交時下面的table擷取到表單裡面的資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.