我试图将两个变量从ngRepeat传递给一个函数,但似乎我错过了一些东西。有人可以解释它是什么吗?
-1
<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>
答案 0 :(得分:2)
您应该从object
ng-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
}