AngularJs向ng repeat添加新数据
我创建了一个小应用程序。我使用实时数据库。首先,我使用查询从数据库中获取数据。将记录添加到数据库时。我可以得到这些数据。但我必须将新数据附加到现有数据中。我如何附加 HTMLAngularJs向ng repeat添加新数据,angularjs,Angularjs,我创建了一个小应用程序。我使用实时数据库。首先,我使用查询从数据库中获取数据。将记录添加到数据库时。我可以得到这些数据。但我必须将新数据附加到现有数据中。我如何附加 HTML <tr ng-repeat="i in result track by $index"> <td>{{i.id}}</td> <td>{{i.category}}</td> <td>{{i.status}}</td>
<tr ng-repeat="i in result track by $index">
<td>{{i.id}}</td>
<td>{{i.category}}</td>
<td>{{i.status}}</td>
</tr>
数据
First query result
data = [
{id:1, category:2, status:1},
{id:2, category:1, status:2}
];
New data result
newData = [{id:3, category:1, status:2}];
康卡特正在工作。但秩序不起作用。我想看看最后的数据top@Hermes$scope.result=data.concat($scope.result)就可以了
First query result
data = [
{id:1, category:2, status:1},
{id:2, category:1, status:2}
];
New data result
newData = [{id:3, category:1, status:2}];
Try this:
var app = angular.module('socket', []);
app.controller('homeController', function ($scope) {
var socket = io.connect('http://localhost:3000');
$scope.result = []
socket.on('list', function (data) {
$scope.result = $scope.result.concat(data);
if (!$scope.$$phase) $scope.$apply();
});
});