1

I have a select like:

<select multiple ng-multiple="true" ng-model="selectMulti" ng-options="br.Name for br in branches"></select>

Scope objects in controller are as below:

vehicleFactory.getBranches().success(function (data) {
    $scope.branches = data;
}).error(function (data) {       
    $scope.loading = false;
});

vehicleFactory.getVehicle().success(function (data) {
    $scope.vehicle = data;
    $scope.selectMulti = $scope.vehicle.AssociatedBranches;
}).error(function (data) {       
    $scope.loading = false;
});

It is not selecting multiple items in select as it was not binding.

What is wrong in it.

1
  • Please share more code Commented Feb 4, 2015 at 5:28

1 Answer 1

1

When you use <select multiple..> the ViewModel of it is an array (unlike <select> without multiple).

So, say you have:

$scope.branches = [{...}, {...}, ...];

and the View:

<select multiple ng-model="selectMulti" ng-options="br.Name for br in branches">
</select>

Then, if you would like to select default values, your $scope.selectMulti should be an array of these values:

$scope.selectMulti = [$scope.branches[0], $scope.branches[1]];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.