使用AngularStrap select元素的Onchange事件

Fou*_*rat 3 angularjs angular-strap twitter-bootstrap-3


我想在select元素的值发生变化时执行一个函数(angular-strap中的select元素是html标签)
我的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>
Run Code Online (Sandbox Code Playgroud)

我的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'}];
Run Code Online (Sandbox Code Playgroud)

我尝试在控制器中添加带有函数的ng-click指令,但是当元素发生变化时,它会在点击时捕获当前所选值的值

谢谢

Mal*_*kus 5

有一些选项正在使用ngChange Reference

另一种是使用$watch.请参阅api参考的$ watch部分scope

使用示例watch (这将在您的控制器中)

$scope.$watch('selectedCriteria', function() {
     $scope.SomeFunction();
});
Run Code Online (Sandbox Code Playgroud)

一个使用的例子 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>
Run Code Online (Sandbox Code Playgroud)