如果我们选择了选定的值,则角度选择更改事件不会触发

时间:2018-03-30 08:50:42

标签: angularjs events

即使我们选择了已选择的值

,是否还有其他事件可以获得select值
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
$scope.update = function() {
console.log('updated')
}
}

https://jsfiddle.net/gh7b30kj/2/

1 个答案:

答案 0 :(得分:0)

试试这段代码

     <div ng-controller="MyCtrl">

 <select  name="abc"  ng-model="item" ng-change="update(item)" >
              <option value="">Select</option>
              <option name="age" ng-value="{{size.code}}" ng-repeat="size in sizes"
                 value="{{size.code}}" >
                 {{size.name  }}
              </option>
           </select>


{{item.code}} {{item.name}}
</div>

控制器

 var myApp = angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
 $scope.sizes = [ {code: 1, name: 'n1'}, {code: 2, name: 'n2'}];
 $scope.update = function(item) {
 alert(item)
}
}