[英]How to push values from an array to another array before using `splice` method in AngularJS?
I have a AngularJS
method to splice
elements from middle of an array
but I want to add the elements to be deleted to another array before using splice
method. 我有一个
AngularJS
方法来从array
中间splice
元素,但我想在使用splice
方法之前将要删除的元素添加到另一个数组中。 Here is my code 这是我的代码
$scope.method = function (index) {
$scope.array2.push($scope.array1[index]);
$scope.array1.splice(index, 1);
}
when I am calling the method array1[index]
values could be retreived but they not getting pushed into array2
当我调用方法
array1[index]
值可以检索但它们没有被推入array2
here is my html code 这是我的HTML代码
<div data-ng-repeat="item in array1">
<button class="btn btn-success pull-right" data-ng-click="method($index)">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
<br />
</div>
I change only this part of your code. 我只更改您代码的这一部分。
$scope.method = function (index) {
$scope.array2.push($scope.array1.slice(index, 1));
$scope.array1.splice(index, 1);
};
Check this jsfiddle example 检查这个jsfiddle示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.