JSFiddle - React, Tailwind, and code Playground
HTML
<div ng-app='app'>
<div ng-controller="MainCtrl">
<h1> AngularJS revert select on dialog cancel </h1>
<table>
<tbody>
<tr ng-repeat="application in rows">
<td>
<select ng-model="application.selectedVersion" ng-options="apk.versionName for apk in application.versions | orderBy : 'id' : true" ng-init="application.selectedVersion=application.versions.filter(currentVersion, application.apkUpdates)[0]" ng-change="selectionChanged(application, '{{application.selectedVersion}}')"
style="padding:0 1em;" />
</td>
</tr>
</tbody>
</table>
</div>
</div>
JavaScript
var app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
$scope.rows = [{
"id": 1,
"currentVersion": "1.0.1",
"versions": [{
"id": 3,
"versionCode": 3,
"versionName": "1.1.0",
"currentVersion": false
},
{
"id": 1,
"versionCode": 1,
"versionName": "1.0.0",
"currentVersion": false
},
{
"id": 2,
"versionCode": 2,
"versionName": "1.0.1",
"currentVersion": true
}
]
},
{
"id": 5,
"currentVersion": "1.2.0",
"versions": [{
"id": 16,
"versionCode": 3,
"versionName": "1.2.1",
"currentVersion": false
},
{
"id": 17,
"versionCode": 2,
"versionName": "1.2.5",
"currentVersion": false
},
{
"id": 13,
"versionCode": 1,
"versionName": "1.2.0",
"currentVersion": true
}
]
},
{
"id": 3,
"currentVersion": "1.1.0",
"versions": [{
"id": 7,
"versionCode": 1,
"versionName": "1.0.0",
"currentVersion": false
},
{
"id": 9,
"versionCode": 3,
"versionName": "2.0.0",
"currentVersion": false
},
{
"id": 8,
"versionCode": 2,
"versionName": "1.1.0",
"currentVersion": true
}
]
}
];
$scope.selectionChanged = function(application, previousVersion) {
var dialog = confirm('Change version?');
if (dialog) {
console.log('change version confirmed');
} else {
application.selectedVersion = previousVersion;
}
};
$scope.currentVersion = function(application, index, array) {
return application.currentVersion;
};
});