【发布时间】:2016-05-05 14:53:52
【问题描述】:
我创建了一个 plunker,它具有表格并由两个字段组成,名称和年龄正在从表单中保存。保存数据后,每个表格行都会动态生成编辑按钮。
<script>
var app = angular.module('plunker', []);
app.controller('MainCtrl', function ($scope) {
$scope.data=[]
$scope.save=function(form){
$scope.data.push(form)
$scope.form={}
});
</script>
<body ng-controller="MainCtrl">
<hr>
<div class="row">
<div class="col-md-5 col-lg-5">
<form>
<input type="text" class="form-control" ng-model="form.name"><br>
<input type="text" class="form-control" ng-model="form.age"><br>
<button type="button" ng-click="save(form)">save</button>
</form>
</div>
</div>
<table class="table striped">
<tr>
<th>name</th>
<th>age</th>
</tr>
<tr ng-repeat="item in data">
<td>{{item.name}}</td>
<td>{{item.age}}</td>
</tr>
</table>
https://plnkr.co/edit/vBrPlOAitIAALKcbT3Q8?p=preview
请帮助我如何做到这一点
【问题讨论】: