1

我得到了一个有两个ng重复的树状桌子。带参数ngClick不通过参数

<table> 
<tr ng-repeat-start="am in anArray"> 
<td><button ng-click="TheFunction(am)"></button></td> 
</tr> 
<tr ng-repeat-start="em in anotherArray"> 
<td><button ng-click="TheFunction2(em)"></button></td> 
</tr> 
<tr ng-repeat-end></tr> 
<tr ng-repeat-end></tr> 

对于某些功能来显示/隐藏的“正确”线在屏幕上显示的结果是用具有一个按钮的每一行中调用的范围限定的功能的树。 在控制器I中定义的功能:

$scope.TheFunction=function(am){ 
alert(am); //and other things to do with the am object 
} 
$scope.TheFunction2=function(em){ 
alert(em); //and other things to do with the am object 
} 

如果我运行的页面,树状构建体如预期工作,所有的按钮被示出。如果我点击一个按钮,就会调用正确的函数。但是,当我检查传递的参数时,它是未定义的。

有什么我错过了吗?

+0

为什么不用NG重复和摆脱NG-重复端行的? –

+0

我使用开始/结束语法来使它更容易阅读(至少对我来说),它不应该影响我认为的参数传递? – Myko

+0

无法重现[JSF上的此DEMO](https://jsfiddle.net/m3wtdsnL/)的问题。 – georgeawg

回答

1

以下是您的代码。它与ng-repeatng-repeat-start都有效。我用ng-repeat,因为它是清洁..

看看这对你的作品:

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

 
function main($scope){ 
 
    $scope.anArray = ["a", "b", "c"]; 
 
    $scope.anotherArray = ["dog", "cat", "mouse"]; 
 
    $scope.TheFunction=function(am){ 
 
    alert(am); //and other things to do with the am object 
 
    } 
 
    $scope.TheFunction2=function(em){ 
 
    alert(em); //and other things to do with the am object 
 
    } 
 

 
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div ng-app ng-view ng-controller="main"> 
 
<table> 
 
<tr ng-repeat="am in anArray"> 
 
    <td><button ng-click="TheFunction(am)">{{am}}</button></td> 
 
</tr> 
 
<tr ng-repeat="em in anotherArray"> 
 
    <td><button ng-click="TheFunction2(em)">{{em}}</button></td> 
 
</tr> 
 
</table> 
 
</div>

+0

除了未将应用程序和控制器定义复制到“我的”代码中之外,您发生了什么变化? – Myko

+0

使用了'ng-repeat'而不是'ng-repeat-start'和'ng-repeat-end' ..你可以看到这个简单的例子在代码片段中有效。如果你仍然无法使用它,请还张贴您的控制器,包括阵列的一部分.. –

+0

嗯,我仍然不明白为什么你的代码工作,我的不是。 使用start-end-syntax时是否存在已知的错误? – Myko