SchemeSonic
SchemeSonic

Reputation: 386

Select "selected element" again from select box angular

Let's say I have the following basic select box html.

<select ng-model="selectedOption" ng-change="showSelected()">
    <option value="">Select Option</option>
    <option value="option-1">Option 1</option>
    <option value="option-2">Option 2</option>
</select>

And following controller:

$scope.showSelected = function () {
        console.log('Selected');
        //TODO
    }

Here, lets say I select 'option-1' first, and then there will be console log. Now I want to select same element again and trigger the function again. However, showSelected() function will not be triggered, because I havent changed the model, it is again 'option-1'.

"ng-click" directive also not working in select box. So I cannot trigger the function by ng-click.

What is the angular way solution for this particular problem?

Upvotes: 0

Views: 191

Answers (2)

Naeem Shaikh
Naeem Shaikh

Reputation: 15715

Here is a work around. JSFIDDLE

<div ng-controller="MyCtrl">
selected val={{}}
 <select ng-model="selectedOption" ng-mouseup="showSelected()">
    <option value="">Select Option</option>
    <option value="option-1">Option 1</option>
    <option value="option-2">Option 2</option>
</select>
</div>



function MyCtrl($scope) {
    $scope.open=false;
    $scope.showSelected = function () {
    if($scope.open) {
    // here s your code for select
        console.log('Selected');
    }
    $scope.open=!$scope.open;
    }
}

Upvotes: 1

Laurent Pitteloud
Laurent Pitteloud

Reputation: 41

Why do you want to trigger once again the event ? If you have to do so, just reset your selectbox, then the event will be triggered again.

Upvotes: 0

Related Questions