How can I get the Broken example (below) to work without changing it from an array (as I have a lot of code that depends on it being an array in other parts of the application)?
I'd like to continue using an array but I'd like the correct select option to show when the model changes. The model changes correctly when the button is clicked but the option isn't being found in the select (ng-model and ng-options just aren't matching up when it's an array).
angular.module('app', [])
.controller('MainCtrl', ['$scope', function($scope) {
$scope.valueWorking = 'value1';
$scope.selectFilterWorking = [{name: 'name1', value: 'value1'},{name: 'name2', value: 'value2'}];
$scope.valueBroken = ['value1'];
$scope.selectFilterBroken = [{name: 'name1', value: ['value1']},{name: 'name2', value: ['value2', 'value3']}];
}]);
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<div ng-app="app" ng-controller="MainCtrl">
<strong>Working</strong> (SELECT <i>is</i> updated when ng-model is a string):<br>
<select ng-model="valueWorking"
ng-options="select.value as select.name for select in selectFilterWorking">
<option value="">Select an Option</option>
</select>
<button ng-click="valueWorking='value2'">Assign to String of 'value2'</button> {{valueWorking}}<br><br>
<strong>Broken</strong> (SELECT <i>not</i> updated when ng-model is an array):<br>
<select ng-model="valueBroken"
ng-options="select.value as select.name for select in selectFilterBroken">
<option value="">Select an Option</option>
</select>
<button ng-click="valueBroken=['value2','value3']">Assign to Array of ["value2","value3"]</button> {{valueBroken}}
</div>
Upon clicking 'Run code snippet' above, notice that the initial option is not selected (on the Broken select, when it's an array), but is initially selected on the Working select when it's a string. The correct option is also not shown when 'Assign to Array of ["value2"]' is clicked.
UPDATE: I'm trying to get the OPTIONS ($scope.selectFilterBroken) to match the MODEL, rather than the other way around - hence my need to keep the model as an array. The button click is merely to simulate the other parts of the application that manipulate the array.
Any help would be great. Thanks and please.