Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.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
将参数从html传递到Java中的javascript_Javascript_Angularjs_Angularjs Scope - Fatal编程技术网

将参数从html传递到Java中的javascript

将参数从html传递到Java中的javascript,javascript,angularjs,angularjs-scope,Javascript,Angularjs,Angularjs Scope,我有一个javascript函数,我应该向它传递一个参数 <tr ng-repeat="restaurant in accounts.selectedRestaurants"> <td >{{restaurant}}</td> <td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td> </tr> <body> <div ng-

我有一个javascript函数,我应该向它传递一个参数

<tr  ng-repeat="restaurant in accounts.selectedRestaurants">
  <td >{{restaurant}}</td>
   <td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td>
</tr>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<table>
<tr ng-repeat="product in products">
<td ng-init="Y(product)">{{product}}</td>
</tr>
</table>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.products=[11,22,33];
$scope.Y= function(ar)
 {
 alert(ar);
 };
});
</script>
</body>
我的函数是accounts.findalAccountsByRestaurant,参数是restaurant,从ng-repeat中检索。如何将此参数传递给函数?请提前感谢。

尝试执行以下操作:

<tr  ng-repeat="restaurant in accounts.selectedRestaurants">
  <td >{{restaurant}}</td>
   <td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td>
</tr>
像这样试试

<tr  ng-repeat="restaurant in accounts.selectedRestaurants">
  <td >{{restaurant}}</td>
   <td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td>
</tr>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
<table>
<tr ng-repeat="product in products">
<td ng-init="Y(product)">{{product}}</td>
</tr>
</table>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.products=[11,22,33];
$scope.Y= function(ar)
 {
 alert(ar);
 };
});
</script>
</body>

如果您正确定义了范围,则一切都应按原样工作:


是的,但我不需要TDA中的按钮,所以您想在数组上循环并为每个对象调用函数?是的,准确地说,但我应该在td中调用函数,而不是在$scope上定义的按钮中调用函数?如果是这样的话,你的代码应该可以工作。谢谢你的回复。这对我很有帮助。我有一个小问题,我不知道它的来源。我会把它放在主贴上,回答完后请不要改变你的问题。针对新问题提出新问题。