[英]Angular -js :ng-model not working with searchable dropdown
I have implemented a searchable dropdown using this library ( https://select2.github.io/ ), its works fine but i can't get the ng-model
value when the button is clicked. 我已经使用此库( https://select2.github.io/ )实现了可搜索的下拉列表,其工作正常,但单击按钮时我无法获得ng-model
值。
<select ng-model="destination_name" class="js-example-basic-single form-control" >
<option selected disabled>Choose</option>
<?php foreach ($all_dest as $value): ?>
<option value="<?=$value->id?>"><?=$value->destination_name?></option>
<?php endforeach; ?>
</select>
<input type="button" ng-click="addDest(destination_name)" value="{{btnTxt}}" name="add" class="btn btn-primary pull-right"/>
jquery for searchable dropdown jQuery的可搜索下拉菜单
$(document).ready(function() {
$(".js-example-basic-single").select2();
});
Angular js code Angular JS代码
$scope.addDest=function (value) {
alert(value);
}
here addDest
is the function that passes the selected value in the dropdown menu when the button is clicked I will get undefined
even if an item is selected. 这里的addDest
是在单击按钮时在下拉菜单中传递所选值的函数,即使选择了某个项目,我也将undefined
。
NOTE 注意
when i hide the jquery
part it provides the searchable dropdown menu i will get the ng-model
value. 当我隐藏jquery
部分时,它提供了可搜索的下拉菜单,我将获得ng-model
值。 I think its the problem with jquery part. 我认为这是jquery部分的问题。
Best solution - use https://github.com/angular-ui/ui-select instead of your select. 最佳解决方案-使用https://github.com/angular-ui/ui-select代替您的选择。
Next solution - write wrapper directive and sync scope with select via 下一个解决方案-编写wrapper指令,并通过select via同步作用域
$scope.$apply();
on select2 change event; 在select2更改事件上;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.