我正在使用angularfire来保存和显示我的用户数据。他们填写的表单堆叠或复制数据而不是更新。我只想要一个显示最新数据,任何想法?我将它全部包含在一个面板中,用户名等内容列出了3次。
app.controller('infoCtrl', ['$scope', '$location', '$firebaseArray', 'Auth',
function($scope, $location, $firebaseArray, Auth) {
this.userAuthData = Auth.$getAuth();
vm = this;
var ref = new Firebase('https://capstone-zhf.firebaseio.com/' + this.userAuthData.uid + '/surveyInfo');
ref.orderByChild('name').limitToLast(2).on("child_added", function(snapshot) {
});
vm.syncObject = $firebaseArray(ref);
var newInfo = {};
$scope.addInfo = function() {
vm.syncObject.$add({
q1: vm.newInfo.q1,
q2: vm.newInfo.q2,
q3: vm.newInfo.q3,
q4: vm.newInfo.q4,
q5: vm.newInfo.q5,
q6: vm.newInfo.q6,
q7: vm.newInfo.q7,
weight: vm.newInfo.weight,
height: vm.newInfo.height,
name: vm.newInfo.name
});
vm.newInfo = {};
};
这是我的HTML代码
<table>
<tr ng-repeat="(id, info) in infoCtrl.syncObject">
<td class="panel-body">Goal: {{ info.q1 }}</td>
<td class="panel-body">{{ info.q2 }}</td>
<td class="panel-body">{{ info.q5 }}</td>
<td>
<button ng-click="editNew(info)">Edit</button>
</td>
<td>
<button ng-click="infoCtrl.syncObject.$remove(id)">x</button>
</td>
</tr>
</table>