选项未突出显示

时间:2019-03-26 11:08:17

标签: javascript html angularjs

我有多个选择选项,然后选择所有按钮。单击全选按钮时,所有选项应突出显示。但是,以我为例,当单击“全选”按钮时,我将所有选项都选中,并显示了其值,但这些选项未突出显示。

这是我的控制器代码。

$scope.selectedAll = function(){
    $scope.user.profile = []; 
    angular.forEach($scope.userprofiles, function(item){
        $scope.user.profile.push( item.profile);
    }); 
}

HTML:

<div class="label_hd">Profiles
    <input type="button" 
           id="select_all" 
           ng-click="selectedAll()" 
           name="select_all" 
           value="Select All">
</div>
<select multiple 
        class="browser-default" 
        name="userprofile" 
        id="userprofile"
        ng-model="user.profile">
    <option ng-repeat="profile in userprofiles"
            value="{{profile.profile}}">
            {{ profile.profile_name }}
    </option>
</select>

1 个答案:

答案 0 :(得分:0)

这里是一个小提琴:https://jsfiddle.net/MSclavi/zybnjpot/12/

您在正确的道路上。不要使用ng-repeat,而是要使用ng-options。这是文档https://docs.angularjs.org/api/ng/directive/ngOptions。祝你好运