頁面引入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"/>