I have a form with two text boxes, one for entering a name and the other for an email. There is also a button to add a new row with these two text boxes. I am attempting to retrieve the values of Name and Email using AngularJS, but I am new to Angular.
Below is my code snippet:
JavaScript
function addrow() {
var table = document.getElementById("emp");
var row = table.insertRow(2);
var name = row.insertCell(0);
var email = row.insertCell(1);
name.innerHTML = "<input id='Name' type='text' value='' name='ename' ng-model='data.ename'>";
email.innerHTML = "<input type='text' value='' name='Email' id='email' ng-model='data.email'>";
}
HTML
<form name="employees" ng-submit="emp()">
<table id="emp">
<tr>
<td>Employee Name
</td>
<td>Employee Email
</td>
</tr>
<tr>
<td>
<input type="text" id="Name" name="ename" ng-model="data.ename" />
</td>
<td>
<input type="email" id="email" name="email" ng-model="data.email" />
</td>
</tr>
</table>
<button class="btn btn-primary" onclick="addrow();">Add new</button>
<input type="submit" class="btn" />
</form>
AngularJS
var model1Controller = ["$scope", "$http", function ($scope, $http) {
$scope.data = [];
$scope.emp = function () {
alert($scope.data.ename);
}
}]