jeudi 30 juin 2016

How to get alert when Ichange dropdown options using angularjs

This is my dropddown menu, when I change the option will get alert its working, but when i select again on the same option i didnt get alert.How it posiible

index.html

<body ng-app="demoApp">
    <div ng-controller="DemoController">
    <div>
     <select ng-model="currentlySelected" ng-options="opt as opt.label for opt in options" ng-change="logResult()">
        </select>

        The value selected is {{ currentlySelected.value }}.
    </div>

    </div>
</body>

app.js

angular.module('demoApp', []).controller('DemoController', function($scope) {

  $scope.options = [
    { label: 'one', value: 1 },
    { label: 'two', value: 2 }
    { label: 'three', value: 3 }
    { label: 'four', value: 4 }
    { label: 'five', value: 5 } 
  ];
  $scope.currentlySelected = $scope.options[1];

    $scope.logResult = function() {
     alert($scope.currentlySelected);   
    }
});

What I expect is if I select "two" twice i need to alert twice. Is this possible or should I be using a different directive for this?

Aucun commentaire:

Enregistrer un commentaire