У меня есть функция javascript, которой я должен передать параметр. Этот параметр должен быть извлечен из html, как это
<tr ng-repeat="restaurant in accounts.selectedRestaurants">
<td >{{restaurant}}</td>
<td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td>
</tr>
моя функция - accounts.findAllAccountsByRestaurant(), а параметр - ресторан, который извлекается из ng-repeat.Как я могу передать этот параметр функции? Спасибо заранее.
Если вы правильно определили сферу действия, все должно работать так: http://jsfiddle.net/jpwup7Lb/5/
$scope.accounts={
selectedRestaurants:
["one","two","three"],
findAllAccountsByRestaurant:function(restaraunt){
return "here all accounts for "+restaraunt;
}
}
попробуйте сделать это:
<tr ng-repeat="restaurant in accounts.selectedRestaurants">
<td >{{restaurant}}</td>
<td>{{accounts.findAllAccountsByRestaurant(restaurant)}}</td>
</tr>
Затем в вашем контроллере
$scope.accounts.findAllAccountsByRestaurant = function(restaurant) { return alert(restaurant); };
попробуй вот так
<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>