lakshman chanapathi lakshman chanapathi - 1 year ago 89
HTML Question

Angularjs highlighting multiple options with given array of options in multi select form component

I have an array of selected options and i need to highlight these array of options in select component among all available options..

Answer Source

The standard behavior already highlights the selected options. Example below. In the example two options are selected by default.

  .module('exampleApp', [])
  .controller('ExampleController', ExampleController);

function ExampleController() {
  var vm = this;
  vm.options = [{
    id: '1',
    name: 'Option A'
  }, {
    id: '2',
    name: 'Option B'
  }, {
    id: '3',
    name: 'Option C'
  vm.selectedOptionNames = ['Option B', 'Option C'];
<!DOCTYPE html>
<html ng-app='exampleApp'>

  <script src=""></script>

<body ng-controller="ExampleController as vm">
  <form name="myForm">
    <label for="multipleSelect">Make a choice:</label>
    <select name="multipleSelect" id="multipleSelect" ng-options=" as for option in vm.options" ng-model="vm.selectedOptionNames" multiple>