Angular JavaScript编码问题

时间:2016-06-07 07:20:55

标签: angularjs angularjs-directive angular angularjs-scope

Angular JS代码。 2个列表,每个列表中都有项目,单击列表中的项目,该项目从该列表中删除并添加到另一个

寻找可重用性:

$scope.move=function(index){
      $scope.list2.push($scope.list1[index]);
      $scope.list1.splice(index,1);
    }

1 个答案:

答案 0 :(得分:1)

这很简单:https://plnkr.co/edit/xxTpvxB9GSwAqy25s5GN?p=preview

<body ng-controller="MainCtrl">
  <p>List1</p>
  <div ng-repeat="item in list1">
    <a href="" ng-click="move($index);">{{item}}</a>
  </div>
  <hr/>
  <p>List2</p>
  <div ng-repeat="item in list2">{{item}}</div>
</body>

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.list1 = [
    "12",
    "13",
    "14"
    ];
    $scope.list2=["223"];

    $scope.move=function(index){
      $scope.list2.push($scope.list1[index]);
      $scope.list1.splice(index,1);
    }
});