这就是我为品牌渲染下拉菜单的方式。
<div class="col-md-3">
<select
ng-options="brand.id as brand.name for brand in brands"
ng-model="selectedBrand"
ng-change="update(selectedBrand);">
<option value="">Select Brand</option>
</select>
</div>
在更改时我想调用更新函数。这是 Controller 中的更新功能。
$scope.update = function(selectedBrand){
alert ($scope.selectedBrand.name);
alert (selectedBrand.id);
}
但是这两个警报都给我未定义的信息。
如何正确传递所选品牌,以便我可以在 Controller 中获取它?
最佳答案
试试这个--
<div class="col-md-3">
<select
ng-options="brand as brand.name for brand in brands"
ng-model="selectedBrand"
ng-change="update(selectedBrand);">
<option value="">Select Brand</option>
</select>
</div>
在 Controller 中
scope.selectedBrand={};
关于javascript - 如何在 angularJS 中将所选品牌从下拉列表传递到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40857781/