我正在尝试使用角度ng选项实现loudev multiselect。问题是,它没有返回错误,但选择列表为空。
<select ng-options="item.label for item in list"
lp-multi-select multiple="multiple"
class="multi-select" ng-model="$scope.selected"></select>
答案 0 :(得分:0)
你不能写&#34; $ scope&#34;在ng模型中,因为它没有在那里定义。所以规则是&#34; $ scope.selected&#34;在角度控制器中,js与&#34;选择&#34;相同。在ng-model中 -
NG-模型=&#34;选择&#34;
如果您这样做,那么它会将您选择的多个选项作为对象数组返回。您可以看到下面的示例(选择两个选项,然后单击检查按钮查看结果) -
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="datCtrl">
<select ng-options="item.label for item in list" multiple="multiple" class="multi-select" ng-model="selected">
</select>
<button ng-click="checkM()">Check</button>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('datCtrl', function ($scope) {
$scope.list=[{id:1,label:"banana"},{id:2,label:"mango"},{id:3,label:"apple"},{id:4,label:"water melon"}];
$scope.checkM=function (){
console.log($scope.selected);
};
});
</script>
</body>
</html>
&#13;