Onchange event with AngularStrap picker


I want to execute a function when the value of a select element changes (select element in angular-strap is html tag)
My HTML:

 <button type="button" class="btn btn-default" ng-model="selectedCriteria" data-html="1" ng-options="choice.value as choice.label for choice in selectChoices" bs-select>
      Action <span class="caret"></span>
    </button>

      

My JS:

$scope.selectedCriteria = "Location";
$scope.selectChoices = [{'value':'Location','label':'<i class=\'fa fa-map-marker\'></i> Location'},
{'value':'Age','label':'<i class=\'fa fa-male\'></i> Age'}];

      

I tried to set the ng-click directive with a function in the controller, but it locks the value of the currently selected value on click not on element change

thank

+3


source to share


1 answer


There are several options that you use ngChange

Link

Another is using $watch

. See the $ watch section in the scope

api link

Example usingwatch

(this will be in your controller)



$scope.$watch('selectedCriteria', function() {
     $scope.SomeFunction();
});

      

Example using ngChange

<button type="button" class="btn btn-default" 
   ng-change="SomeFunction()"
   ng-model="selectedCriteria" data-html="1" 
   ng-options="choice.value as choice.label for choice in selectChoices" bs-select>
      Action <span class="caret"></span>
</button>

      

+5


source







All Articles