尝试实现 ng-repeate 和表单之间的双向绑定

trying to achieve two way binding between ng-repeate and a form

本文关键字:绑定 之间 表单 实现 ng-repeate      更新时间:2023-09-26

ng-repeate 中选定行的值将填充在其下方的表单中。 为了实现这一目标,我正在做一件简单的事情

<p ng-repeat="item in  array" ng-click="SetCurrVariable(item)">
   {{item.ThresholdSet}}
</p>

在控制器中我有一个功能

  $scope.array = [
        {  ThresholdSet: false },
        { ThresholdSet: false },
        {  ThresholdSet: false }
    ];
  $scope.SetCurrVariable = function (variable) {
        $scope.CurrVariable = variable;
    };

表单有一个复选框,我绑定到CurrVariable的属性

     <input id="chkThr" type="checkbox" ng-model="CurrVariable.ThresholdSet">

我正在尝试实现这种行为,如果我单击表单中的复选框。更改在 ng-repeate 中可见,就像双向绑定一样。

普伦克尔设置

已更新$scope

 $scope.SetCurrVariable = function (variable) {
    $scope.CurrVariable = variable;
};

在控制器中使用此代码,则双向绑定应该可以工作