I´d like to pre-select a select-field from a given Restful-Service:
$scope.findOne = function () {
$scope.teams = Teams.query();
$scope.teamCategory = TeamCategories.get({
teamCategoryId: $stateParams.teamCategoryId
});
};
This is my function to get one Team-Category from my database.
<select name="assignedTeams" size="10" id="assignedTeams" multiple class="form-control" data-ng-model="teamCategory.assignedTeams" ng-options="team._id as team.detailName for team in teams" required>
<option value="">Please choose.</option>
</select>
and this is my select-Field. Both Services return the correct results, I can see them in the console. But the select-Field is not pre-selected. Where is my fault?
You need to make $scope.teamCategory.assignedTeams be an array that only contains the team ids you want to select. It should look like the following:
$scope.teamCategory.assignedTeams = [1,2,3];
The values 1, 2, 3 should be the teams ids you want selected.
I got it to work. The Restful-Service should not populate the response - then the selectFields are correctly set.
Thanks to your help!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.