1

2つのng-repeatsを持つtreelikeテーブルがあります。いくつかの機能でngClick withパラメータはパラメータを渡しません

<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> 

画面上に結果がスコープで定義された関数を呼び出すためのボタンを有し、各列を持つツリーが「正しい」行を非表示/表示します。私は、ページを実行すると、ツリー状の構造が正常に機能している

$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-repeatを使用しましたか? –

+0

私は読みやすく(少なくとも私のために)始める/終わりの構文を使用しています。 – Myko

+0

[このDEMO on JSFiddle](https://jsfiddle.net/m3wtdsnL/)の問題を再現できません。 – georgeawg

答えて

1

これはあなたのコードです。ng-repeatng-repeat-startの両方で動作しました。 ngのリピートを使用して、NG-リピートエンドの行を取り除くない理由

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

アプリとコントローラの定義を除いて、正確に何を変更しましたか?私は 'my'コードにコピーしませんでしたか? – Myko

+0

は、 'ng-repeat-start'と' ng-repeat-end'の代わりに 'ng-repeat'を使用しました。この簡単な例がスニペットで動作することがわかります。また、配列を含むコントローラの部分を投稿します。 –

+0

ええ、私はまだあなたのコードが動作していると私は理解していない。 start-end-syntaxを使用する際に既知のバグはありますか? – Myko

関連する問題