Angularjs 如何将一个元素从一个ng重复推送到另一个ng重复中

Angularjs 如何将一个元素从一个ng重复推送到另一个ng重复中,angularjs,Angularjs,问题是我不知道,我也不知道怎么做标题上写的。如何获取其链接被单击的元素,然后将其值推送到数组中 来自app.js $scope.orderList = []; $scope.add = function() { $scope.orderList.push($scope.pizza.name); }; from view.html <div ng-controller="orderCtrl"> <input type="text" ng-model="

问题是我不知道,我也不知道怎么做标题上写的。如何获取其链接被单击的元素,然后将其值推送到数组中

来自app.js

  $scope.orderList = [];
  $scope.add = function() {
    $scope.orderList.push($scope.pizza.name);
  };
from view.html

<div ng-controller="orderCtrl">
  <input type="text" ng-model="search" placeholder="{{placeholder}}" ng-focus="example()" ng-blur="default()" />
    <ul ng-hide="pizzaSvg">
      <li ng-repeat="pizza in pizze | filter:search | orderBy: 'name'" ng-model="orderList"><a href="" ng-click="add()">{{pizza.name}}</a><br/>{{pizza.ingredients}}</li>
    </ul>
    <ul ng-show="pizzaSvg">
      <li ng-repeat="order in orderList"><a href="">[x]</a> {{order}}</li>
    </ul>
</div>


  • {{{pizza.components}
  • {{order}

您需要将比萨饼作为参数传递给add函数:

  $scope.orderList = [];
  $scope.add = function(pizza) {
    $scope.orderList.push(pizza.name);
  };
然后在html中:

<div ng-controller="orderCtrl">
  <input type="text" ng-model="search" placeholder="{{placeholder}}" ng-focus="example()" ng-blur="default()" />
    <ul ng-hide="pizzaSvg">
      <li ng-repeat="pizza in pizze | filter:search | orderBy: 'name'" ><button ng-click="add(pizza)">{{pizza.name}}</button><br/>{{pizza.ingredients}}</li>
    </ul>
    <ul ng-show="pizzaSvg">
      <li ng-repeat="order in orderList"><button>[x]</button> {{order}}</li>
    </ul>
</div>

  • {{{pizza.name}}
    {{{pizza.配料}
  • [x]{{order}

另外,避免对可单击的元素使用
,通常像
这样的操作会更干净,因为浏览器不会尝试跟随链接作为其默认的
单击操作。

我通常会使用如下按钮:

<ul ng-show="pizzaSvg">
  <li ng-repeat="order in orderList"><button ng-click="add(order)">[x]</a> {{order}}</li>
</ul>
  • [x]{{order}

原因是,在我的视图中,一个链接是用来从一个页面移动到另一个页面的,其中一个按钮将用于执行一个操作。

Uhm orderList保持其自身为空:-/@EmanueleTuttolani,可能是
ng show=“pizzaSvg”
阻止了orderList的显示?不,因为我甚至把
{orderList}
在ul之外,它只是没有被推送。您的第一次ng重复有一个虚假的
ng model=“orderList”
,它可能覆盖了您推送的值。如果它能起到任何作用,这是有效的:
$scope.remove=function(pizza){var index;index=$scope.orderList.indexOf(pizza);$scope.orderList.splice(index,1);}
按钮(ng click=“remove()”)Rimuovi
这是在.jade中