我想简单地得到了previous价值,并从下拉列表中选择新的价值。在这个例子中,下拉是$ P $对填充在当前组的用户被分配。
I'm trying to simply get the previous value, and the newly selected value from a drop-down. In this example, the drop-down is pre-populated with the current group the user is assigned.
在下拉被改变,我希望能够返回旧值和新值。我已经可以得到旧的价值,但我不知道如何返回新值。
When the drop-down is changed, I want to be able to return the old value and the new value. I can already get the old value, but I don't know how to return the new value.
控制器code:
// User Object
userAccess = [{"user_name":"dodsosr11",
"group_level":1,
"user_id":500,
"group_id":10,
"group_name":"Conferences_Admins"},
{"user_name":"keatikj09",
"group_level":1,
"user_id":250,
"group_id":10,
"group_name":"Conferences_Admins"},
{"user_name":"malinag10",
"group_level":1,
"user_id":492,
"group_id":10,
"group_name":"Conferences_Admins"}];
//Group Object
groupAccess = [{"group_name":"Conferences_Admins",
"id":10,
"level_id":1},
{"group_name":"ticket_sales",
"id":59,
"level_id":3},
{"group_name":"Web Developers",
"id":1,
"level_id":1}];
$scope.reassignUser = function(){
var oldGroup = this.user.group_id;
var newGroup = ?????
};
HTML
<tr ng-repeat="user in userAccess">
<td>{{ user.user_name}}</td>
<td>
<select ng-change="reassignUser()"
ng-model="user.group_name"
ng-options="g.group_name as g.group_name for g in groupAccess">
</select>
</td>
</tr>
我创建了一个小提琴这里使用在下面的第一个响应中提供的手表的例子。 http://jsfiddle.net/LHz9D/1/
您可以用NG-点击,因为点击更改之前发生了,你就在那里注册的旧值这样
you could use ng-click, since click happens before change you could there register the old value like this
<select ng-model="selected" ng-change="change(selected, oldValue)" ng-click="oldValue = selected">
和在控制器
$scope.change = function(newValue, oldValue){
//do if's in case you use null or empty values
if ( oldValue ) {
//do something
}
if ( newValue ) {
//do something
}
}