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.
Controller 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>
I've created a fiddle here using the watch example that was provided in the first response below. http://jsfiddle.net/LHz9D/1/
Try like this
View
<select ng-model="selected" ng-change="change(selected, {{selected}})">
JS
$scope.change = function(newObj, oldObj){
console.log(newObj);
console.log(oldObj);
}