I have a dropdownlist as follows:
<tr ng-repeat="role in rolesList" align="center">
<div class="form-group">
<td></td>
<td align="center">
<select ng-model="rolesList[$index]" class="form-control" ng-change="enableClick()"
ng-options="role.name for role in roles | filter : exclude(rolesList[$index])" style="float:left; width: 340px;" >
<option value="">Select Role to assign</option>
</select>
<button type="button" class="btn btn-danger btn-sm"
ng-click="removeDropDownList($index)"
style="float:left; position: relative; left: 10px;">
<span class="glyphicon glyphicon-minus"></span></button>
<div> <br></div>
</td>
</div>
</tr>
in my controller method which populates the dropdwnlists is as follows:
$scope.openUpdateForm = function (userType) {
$scope.UserTypeDetail.name=userType.name;
$scope.UserTypeDetail.id=userType.id;
$scope.rolesList =userType.role;
for (var j=0;j<userType.role.length;j++) {
$scope.rolesList[j]=userType.role[j];
}
$('#UserTypeModal').modal('show');
};
where userType consist of data like :
[{"id":2,"name":"ADMIN","role":[{"id":2,"name":"ROLE_JOBS_MASTER"},{"id":3,"name":"ROLE_CUSTOMER_CARE"},{"id":4,"name":"ROLE_SMS_TEMPLATE"},{"id":6,"name":"ROLE_CITY_HUBS"},{"id":7,"name":"ROLE_USER"}],"companyId":2},{"id":12,"name":"fvcawds","role":[{"id":6,"name":"ROLE_CITY_HUBS"},{"id":3,"name":"ROLE_CUSTOMER_CARE"}],"companyId":2},{"id":3,"name":"fvcawds5tyre hdh","role":[{"id":6,"name":"ROLE_CITY_HUBS"},{"id":2,"name":"ROLE_JOBS_MASTER"}],"companyId":2}]
My problem is that I get multiple dropdownlists generated accordingly with the roles associated but no option is pre selected.Can anyone help me out with that.
I have referred the question How to set a selected option of a dropdown list control using angular JS ,but the solution didn't work for me.