我有一个角JS:$scope.messages = [];的数组
在模板中我做ng-repeat
<div ng-repeat="item in messages"></div>当我尝试向数组的末尾添加一个新元素时,如下所示:
angular.forEach($scope.messages, function (value, key) {
$scope._lastMsg = key; // Get key of last element of array
});
$scope.messages[++$scope._lastMsg] = obj; // Do increment of next key and add new element obj这种方式添加元素,而不是在数组的末尾,总是不同。
发布于 2015-05-10 09:29:26
试着用Array.push()把它推到最后
$scope.messages.push(obj)https://stackoverflow.com/questions/30149753
复制相似问题