Angularjs Anjularjs在每次选择更改时调用控制器方法

Angularjs Anjularjs在每次选择更改时调用控制器方法,angularjs,Angularjs,关于angularjs的基本问题。我有两种模式:预订和餐桌。我显示了一个预订列表,然后当用户为预订选择表时,我想更新表模型以包含预订 <tr ng-repeat="reservation in reservations"> <td><select ng-model="selectedTable" ng-options="table.name for table in tables"> </td> 本质上,我需要的是,无论何时选择一个表,我都需

关于angularjs的基本问题。我有两种模式:预订和餐桌。我显示了一个预订列表,然后当用户为预订选择表时,我想更新表模型以包含预订

<tr ng-repeat="reservation in reservations">
<td><select ng-model="selectedTable" ng-options="table.name for table in tables">
</td>

本质上,我需要的是,无论何时选择一个表,我都需要在控制器上的方法中访问保留和表

链接到控制器方法的指令是这样做的正确方法吗?我不知道如何传入变量

谢谢

编辑:


我试着这样做。但由于表是一个对象而不是属性,所以子范围仍然创建属性,而不是对父属性的引用。我还尝试添加“as table.name”,但没有成功

<tr ng-repeat="reservation in reservations">
<td><select ng-model="reservation.selectedTable" ng-options="table.name as table.name for table in   tables">
 </td>

看看你的html,我建议你在
选择
下拉列表中使用
ng change

<select ng-model="selectedTable" ng-options="table.name for table in tables" ng-change="tableSelected(reservation,selectedTable)">

记住
ng repeat
创建新范围。此外,还将为每个ng重复作用域设置
selectedTable

如何设置以使每个ng重复的子作用域引用父作用域?子作用域可以访问父作用域元素。请浏览这个wiki,它解释了范围继承,尽管它看起来很有效,但是anjularjs chome扩展并不总是正确地更新模型
<select ng-model="selectedTable" ng-options="table.name for table in tables" ng-change="tableSelected(reservation,selectedTable)">
$scope.tableSelected=function((reservation,selectedTable) {

}