1

When I update the model, a select box is not getting updated to the value in the model. The select has all the valid options, however, the value from the model is not being selected. In the code below, the value in the model is "FACEBOOK". The mapping to the model is correct because value from the select box saves correctly. The issue is occurring when I load the model on page display.

Here is the html:

<select 
 class="form-control" 
 required 
 ng-model="channel.channeltype" 
 ng-options="obj.name for obj in contactchannels track by obj.id">
</select>

The generated html is:

<select ng-options="obj.name for obj in contactchannels track by obj.id">
  <option selected="?" value="selected"></option>
  <option label="Facebook" value="FACEBOOK">Facebook</option>
  <option label="Skype" value="SKYPE">Skype</option>
  <option label="Instagram" value="INSTAGRAM">Instagram</option>
</select>

thanks in advance,

0

1 Answer 1

0

Use ng-selected instead of selected. You can make it true and false. And also show how you are doing in JS file with scope. If it doesn't work like this, then give ng-change="some_func()" and define that function in JS, $scope.some_func = function() {}

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the reply. The option tags in the first snippet above are generated by angular. ng-change event is not fired when the model is updated in the controller: $http.get('rest/admin/dropdownoptions/', {params: {key: 'ContactChannelEnum'}} ) .then(function(response) { $scope.contactchannels = JSON.parse(response.data); }, );

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.