您能否建议如何按事件选择两个选项的通用功能
$scope.selectionOpt = function($event){
alert($event.target.value);
}
<form>
<select ng-change="selectionOpt($event)">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select ng-change="selectionOpt($event)">
<option value=""></option>
<option value="asia">Asia</option>
<option value="india">India</option>
<option value="europe">Europe</option>
</select>
</form>
我们需要将
ng-model
与 ng-change
一起使用,这样角度就不会出现错误,我们只需传入 ng-model
字段并提醒已传递值!
var myApp = angular.module('myApp', []);
function AppCtrl($scope, $http) {
$scope.dropdown2 = null;
$scope.dropdown1 = null;
$scope.send = function() {
console.log($scope);
}
$scope.selectionOpt = function(optionValue) {
alert(optionValue);
}
}
myApp.controller("AppCtrl", AppCtrl);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.10/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="AppCtrl">
<form>
<select ng-model="dropdown1" ng-change="selectionOpt(dropdown1)">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select ng-model="dropdown2" ng-change="selectionOpt(dropdown2)">
<option value=""></option>
<option value="asia">Asia</option>
<option value="india">India</option>
<option value="europe">Europe</option>
</select>
</form>
<hr/>
dropdown1: {{dropdown1}}<br/>
dropdown2: {{dropdown2}}
</div>
</div>