嵌套元素的Angularjs函数调用问题

嵌套元素的Angularjs函数调用问题,angularjs,nested,Angularjs,Nested,我有一个angulars设置,如下所示,试图模拟一些excel功能,其中我有一个嵌套在ng repeat中的控制器 <tr ng-repeat="lw in lw_list" my-lw ng-model="lw" <td> <!-- next two elements act as an excel cell, one for inputing data, they other for displaying calcualtion result

我有一个angulars设置,如下所示,试图模拟一些excel功能,其中我有一个嵌套在ng repeat中的控制器

<tr ng-repeat="lw in lw_list"   my-lw   ng-model="lw" 
<td>
        <!-- next two elements act as an excel cell, one for inputing data, they other for displaying calcualtion result -->
        <div ng-controller="MyCellCtrl">
            <input type="text" class="inputdiv" ng-model="lw.library.name"   >in</input>                        
            <div  class="output"   ng-bind="getCellValue(lw.library.name)" syle="postion:absolute" contenteditable="True" >out</div> 
        </div>


        <div ng-controller="MyCellCtrl">
           more input / div pairs to act as a new cell      
           .....
        </div>

</td>
我设置了样式表,使输入和输出处于相同的位置,并且隐藏/取消隐藏,这样它们就像excel单元格一样,当您键入公式时,当您离开焦点时,它会更新内容

无论如何,当我在getCellValue函数中放置一个console.log,以显示调用的是控制器的哪个实例,然后键入一个特定的单元格时,我可以看到每个单元格上都调用了getCellValue

在更新输入时,是否有方法调用getCellValue而不在每个实例上调用该方法

我基于本教程中的代码编写了以下代码: 通过在compute函数中放置console.log,可以看到相同的行为。如果将数组增加到20 x 20个元素,则当您键入任何内容时,它开始变慢

在更新输入时,是否有方法调用getCellValue而不在每个实例上调用该方法

或者使用viewChangeListeners作为替代:

function MyCellCtrl($scope) 
  {
  $scope.foo = $scope.lw.library.name;

  this.$viewChangeListeners.push(function(newValue) {
    $scope.foo = getCellValue($scope.foo);
    });
  }
参考资料

function MyCellCtrl($scope) 
  {
  $scope.foo = $scope.lw.library.name;

  $scope.$watch('foo', function(newValue) {
    $scope.foo = getCellValue($scope.foo);
    });
  }
function MyCellCtrl($scope) 
  {
  $scope.foo = $scope.lw.library.name;

  this.$viewChangeListeners.push(function(newValue) {
    $scope.foo = getCellValue($scope.foo);
    });
  }