且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用angularjs动态添加行?

更新时间:2023-12-06 11:02:58

您必须将输入的输入值实际推送到 rows array:

You have to actually push the entered input values into the rows array:

$scope.row.push({
    firstName: $scope.firstName,
    lastName: $scope.lastName
});

我会更新html来阅读:

I'd update the html to read:

<a href="#" class="button" ng-click="addRow()">Add Row</a>
First Name : <input ng-model="firstName" required>
Last Name : <input ng-model="lastName" required>

然后:

And then:

<tr ng-repeat="rowContent in rows">
  <td>{{rowContent.firstName}}</td>
  <td>{{rowContent.lastName}}</td>
</tr>

确保包含正确的角度,并且您的控制器也以正确的方式使用。

Make sure angular is included properly and your controller is being used the right way too.