Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

AngularJS - get previous selected option after ng-click on a ng-repeat

angular.module('myApp', [])
  .controller('myCtrl', ['$scope', function($scope) {
    let selHistory = []
    $scope.selectThing = "val2"
    $scope.recVal = function() {
      if (selHistory.length === 0 || selHistory[selHistory.length - 1] !== $scope.selectThing)
        selHistory.push($scope.selectThing)

      console.log("The history of selections: ", selHistory);
    }
    $scope.recVal(); // push our intiial variable in there

    $scope.revert = function() {
      if (selHistory.length > 0) {
        selHistory.pop();
        $scope.selectThing = selHistory[selHistory.length - 1]
        console.log("The history of selections: ", selHistory);
      }
    }
  }]);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  <select ng-change="recVal()" ng-model="selectThing">
    <option value='val1'>1</option>
    <option value='val2'>2</option>
    <option value='val3'>3</option>
  </select>
  <button ng-click='revert()'>Revert</button>
</div>
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs How to populate ng-style with object of CSS 
Javascript :: angularjs Separate values in select containing 2 object 
Javascript :: angular chart js graph legend colors 
Javascript :: Angular.js : recursive call to an $mdDialog controller 
Javascript :: Se Chartjs horizontal 
Javascript :: StaticInjectorError exception for user defined HttpInterceptor 
Javascript :: EXPO useEffect not called on navigating to same screen 
Javascript :: How do I change this React Navigation v5 code to v6 
Javascript :: Get the childrens of an element in react native using useRef 
Javascript :: Scaling elements proportionally using CSS and JQUERY3 
Javascript :: the given sign-in provider is disabled for this firebase project 
Javascript :: how to set the x and y axis title in plotly express bar 
Javascript :: How can I configure multiple sub domains in Express.js or Connect.js 
Javascript :: to fix a broken class oop javascript 
Javascript :: Using Bind() With BuiltIn JavaScript Function 
Javascript :: javascript get multiple attributes 
Javascript :: Remove # id From URL When Clicked On Href Link 
Javascript :: phaser reverse matrix columns 
Javascript :: how to install ghost js 
Javascript :: Staircase 
Javascript :: maptable elo 
Javascript :: ...args javascript 
Javascript :: give call suggestions while clicking on a contact number in next js 
Javascript :: combining not selector with other jquery 
Javascript :: errors thrown inside asynchronous functions will act like uncaught errors 
Javascript :: How to remove added values with javascript 
Javascript :: recursive function and json object 
Javascript :: Check if a number starts with another number or not js 
Javascript :: js check that interactive element is not focused 
Javascript :: jquery equivalent of number_format( 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =