After a lot of tries and several hours :-(, I need some help:
I'm doing an update for a object in the database.
I'm doing an update for a object in the database all is working except setting the default value in a select.
First try:
<div class="form-group" ng-class="{ 'has-error' : departmentForm.codBoss.$invalid && !departmentForm.codBoss.$pristine }">
<label translate="bosscode"></label>
<select ng-model="vm.codBoss" class="form-control" required>
<option value=""> {{ 'selectBoss' | translate }}</option>
<option ng-repeat="item in vm.chooseBoss" ng-
selected="item.codUser==vm.codBossSelected" value="{{item.codUser}}"ng-selected ="item.codUser == vm.selectedUser">
{{item.name}}, {{item.surname}}, {{item.codUser}}
</option>
</select>
<p ng-show="departmentForm.codBoss.$invalid && !departmentForm.codBoss.$pristine" class="help-block" translate="fieldrequired"></p>
Here the ng-selected is not working... ng-selected is not working. I've checked the typeof and both of them are string. The values for item.codUser are: MM, SM, CM. And try with ng-selected = "item.codUser =='MM'" neither works.
After read here some posts, I've tried to use ng-options:
<div class="form-group" ng-class="{ 'has-error' : departmentForm.codBoss.$invalid && !departmentForm.codBoss.$pristine }">
<label translate="bosscode"></label>
<select name="codBoss" ng-model="vm.codBoss" class="form-control"
ng-options="item.name + ' ' + item.surname + ' ,(' + item.codUser + ')' for item in vm.chooseBoss track by item.codUser"
ng-init="item.codUser == 'MM'">
<option value=""> {{ 'selectBoss' | translate }}</option>
</select>
<p ng-show="departmentForm.codBoss.$invalid && !departmentForm.codBoss.$pristine" class="help-block" translate="fieldrequired"></p>
<br/>
Here I've tried with ng-init or ng-selected.
What am I doing wrong?. All works perfectly with both options except the default selection... I need this becasue in a update all fields all filled with the actual data.
Thanks in advance for your help