我有一个问题。 我需要在ng-change中从select到angular控制器中获取所选对象的强大功能。 我的看法:
<select name="region" id="region_of_birth" class="form-control"
ng-options="item.Id as item.Name for item in regionsList"
ng-model="model.BornRegionId"
ng-change="refreshBornDistricts(item)">
<option></option>
控制器中的功能:
$scope.refreshBornDistricts = function (item) {
console.log(item);
};
所选项目存储在model.BornRegionId中
所以请称之为:
$scope.refreshBornDistricts = function () {
$scope.model.BornRegionId // = your selected ID
};
我不认为Angular会盲目地描述ng-change中的内容,也不会在它触发注册事件时注入select对象的当前值。所以,我认为你不能明确地引用项目。
模型更改传播后,ng-change事件会触发,因此您可以简单地在刷新Born Districts函数中引用绑定模型
$scope.refreshBornDistricts = function () {
console.log($scope.model.BornRegionId);
}