Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 取消按钮功能问题_Angularjs_Angularjs Scope - Fatal编程技术网

Angularjs 取消按钮功能问题

Angularjs 取消按钮功能问题,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我正在尝试实现“取消”按钮功能。单击“应用”按钮后,如果我在单击“取消”按钮后对模式列表进行了任何更改,则必须将这些更改还原回去。例如,最初我检查了空运和联运,单击“应用”后,我还选择了“LTL”。现在我检查了航空、联运和LTL。当我点击“取消”时,我希望LTL应该取消勾选,只有空运和联运保持勾选状态。但它并没有像预期的那样发挥作用。请看我的扑克牌。我甚至使用了角复制,但仍然不起作用 $scope.cancel2 = function(){ angular.copy($

我正在尝试实现“取消”按钮功能。单击“应用”按钮后,如果我在单击“取消”按钮后对模式列表进行了任何更改,则必须将这些更改还原回去。例如,最初我检查了空运和联运,单击“应用”后,我还选择了“LTL”。现在我检查了航空、联运和LTL。当我点击“取消”时,我希望LTL应该取消勾选,只有空运和联运保持勾选状态。但它并没有像预期的那样发挥作用。请看我的扑克牌。我甚至使用了角复制,但仍然不起作用

    $scope.cancel2 = function(){

        angular.copy($scope.modesList, $scope.cancelModesList);
 };

这就是控制器代码的外观():


按照代码现在的方式,您正在用空的cancelModeList替换列表。这是正常的,你会有什么显示了。您只需在cancelModeList中输入一个用作参考的初始列表:

  $scope.cancelModesList = [
  {
    "name": "Air",
    "checked": true,
    "id": "186",
    "type": "group"
  },
  {
    "name": "FTL",
    "checked": false,
    "id": "11114",
    "type": "group"
  },
  {
    "name": "InterModal",
    "checked": true,
    "id": "188",
    "type": "group"
  },
  {
    "name": "LTL",
    "checked": false,
    "id": "185",
    "type": "group"
  }]
然后使用角度复制:

$scope.cancel2 = function(){                
    angular.copy($scope.cancelModesList, $scope.modesList);
};
$scope.cancel2 = function(){                
    angular.copy($scope.cancelModesList, $scope.modesList);
};