Note that there are some explanatory texts on larger screens.

plurals
  1. POAngular adds strange options into select element when setting model value
    primarykey
    data
    text
    <p>I have a select element defined as such:</p> <pre><code>&lt;select name="country_id" id="country_id" required="required" ng-model="newAddressForm.country_id"&gt; &lt;option value=""&gt;Select Country&lt;/option&gt; &lt;option ng-repeat="country in countries" value="{{country.id}}"&gt;{{country.name}}&lt;/option&gt; &lt;/select&gt; </code></pre> <p>All works fine when I'm not setting any kind of value in the directive which contains this select element. But when I do something like <code>newAddressForm.country_id = 98</code>, instead of selecting the option with value 98, Angular injects a new one at the top of the select element, like so:</p> <pre><code>&lt;option value="? string:98 ?"&gt;&lt;/option&gt; </code></pre> <p>What gives? What sort of format is this and why does this happen? Note that if I do a <code>console.log(newAddressForm.country_id)</code> in the directive, I get a normal <code>"98"</code>, it's just weird in the generated HTML.</p> <p><strong>Edit:</strong> <em>Situation update.</em> Switched to using <code>ng-select</code>, but the issue persists. </p> <p>The weird element no longer appears, BUT, now there's another element at the top, one that has only a question mark <code>?</code> as the value, and no label. </p> <p>That's, from what I gathered, Angular's <code>"none selected"</code> option. I still don't understand why it won't select the option I tell it to select, though. </p> <p>Doing <code>newAddressForm.country_id = 98</code> still gives no results. Why is that?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload