JSFiddle - React, Tailwind, and code Playground

by Pankaj Parkar

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) track by apk.id" ng-init="application.selectedVersion=application.versions.filter(currentVersion, application.apkUpdates)[0]" ng-change="selectionChanged(application, '{{application.selectedVersion}}', 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) {
  console.log(previousVersion)
    var dialog = confirm('Change version?');
    if (dialog) {
      console.log('change version confirmed');
    } else {
      application.selectedVersion = previousVersion ? JSON.parse(previousVersion) : null;
    }
    console.log(application)
  };

  $scope.currentVersion = function(application, index, array) {
    return...