ngRepeat 参数到 ngChange 函数

ngRepeat argument into ngChange function

我试图将两个变量从 ngRepeat 传递给一个函数,但我似乎遗漏了什么。谁能解释一下这是什么?

<tr  ng-repeat="user in users"><td>
<select
    ng-model="user.selection"
    ng-options="action.id as action.name for action in userActions"
    ng-change="actionChange(user.selection, user.id)"
    required>
</select></td></tr>

$scope.actionChange = function(selection,id) {
    $log.log(selection) // will display the selection
    $log.log(id) // is undefined
}

你应该 return objectng-options

<select
    ng-model="user.selection"
    ng-options="action as action.name for action in userActions"
    ng-change="actionChange(user)"
    required>
</select>

您未将名称写入函数 & 并将该函数添加到作用域中。

$scope.actionChange =  function(user) {
    $log.log(user.name) // will display the selection
    $log.log(user.id) // is undefined
}

Demo Plunkr