页面引入js文件
<link rel="stylesheet" href="../plugins/select2/select2.css" />
<link rel="stylesheet" href="../plugins/select2/select2-bootstrap.css" />
<script src="../plugins/select2/select2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="../js/angular-select2.js"> </script>
定义下拉框需要展示的数据
//格式必须为{data:[{id,text:"xxx"}]}
//如果查数据库,可以将后台返回的值赋值给$scope.brandList={data:后台数据}
$scope.brandList = {data:[{id:1,text:'联想'},{id:2,text:'华为'},{id:3,text:'小米'}]};
下拉框
//config是封装的数据
//multiple表示可多选
//select2-model 是要向后台提交的数据,将选中的值封装到brandIds
<input select2 select2-model="brandIds" config="brandList" multiple placeholder="选择品牌(可多选)" class="form-control" type="text"/>