Angular JS Implementation form submission when the following table gets the data inside the form

Source: Internet
Author: User
Tags button type

Angular JS Implementation form submission when the following table gets the data inside the form
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<link rel= "stylesheet" href= "Css/bootstrap.min.css"/>
<script src= ". /angular-1.5.5/angular.min.js "></script>




<body ng-app= "MYAPP" ng-controller= "Ctrl" >

<form action= "" >
<p> name <input type= "text" ng-model= "name"/></p>
<p> <input type= "text" ng-model= "age"/></p>
<p> sex <input type= "text" ng-model= "Sex"/></p>

</form>
<button type= "Submit" class= "btn Btn-info" ng-click= "Add ()" > Submit </button>

<table class= "Table table-bordered" >
<thead>
<tr>
<th> name </th>
<th> Age </th>
<th> Sex </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 (); Create an empty array

$scope. Add=function () {
$scope. Object=new object (); Create an empty object to put the data in or (Var Object=new object ())
$scope. object.name= $scope. Name; /* ($scope. object.name) to expand the Name property inside the object */
$scope. object.age= $scope. Age;
$scope. object.sex= $scope. Sex;
$scope. Array.push ($scope. Object);/* Add the data inside the object to the array */
Console.log (this);
Console.log ($scope)
}

})
</script>



Angular JS Implementation form submission when the following table gets the data inside the form

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.