Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've bound newParty.party_type.code model to dropdown. On changing its value from controller it is adding another option with value ? number:2138 ? even if option with value 2138 is already contained in select element.

<select id="partyType" name="partyType" class="ng-valid valid ng-dirty" ng-model="newParty.party_type.code">
   <option value="? number:2138 ?"></option>
   <option value="2138">value 1</option>
   <option value="1689">value 2</option>
</select>

I also tried converting newParty.party_type.code to string in controller. But it still adds new option with value ? string:2138 ?

<select id="partyType" name="partyType" class="ng-valid valid ng-dirty" ng-model="newParty.party_type.code">
   <option value="? string:2138 ?"></option>
   <option value="2138">value 1</option>
   <option value="1689">value 2</option>
</select>

If I select any option manually, model gets correct value. But via controller, it's not working. Why is this happening? How does angular data bindings work? Do I need to be type-aware when dealing with model properties?

EDIT1: Options in select tag are loaded dynamically after page load. (after ng app init) I tried putting some static data and it is working fine. It has something to do with angular not being able to process dynamically loaded data outside angular controllers.

share|improve this question
1  
I will suggest you use ng-options for the dropdown. –  kubuntu Oct 4 '13 at 10:01
    
I just answered the same question here: stackoverflow.com/questions/19182961/… –  geniuscarrier Oct 4 '13 at 15:30
    
Would like to see your controller code, particularly the newParty object and how you are setting the value. –  kmdsax Oct 4 '13 at 15:34
    
@geniuscarrier, "how to set first select always blank" is not the question, he is trying to manually select an option from the controller. –  kmdsax Oct 4 '13 at 15:36
    
I dont have the option to use ng-options because dropdown's options are fetched from other data source than angular models. I tried with static data in above select element and it is working. Here's code snippet –  smitrp Oct 4 '13 at 21:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.