James Lemon
James Lemon

Reputation: 426

ng-model bind to select tag produced empty default value?

DEMO https://jsfiddle.net/z71vqLva/

<select ng-model="data.fields.pax">
              <option>pax</option>
              <option value="1">1 pax</option>
              <option value="2">2 pax</option>
            </select>
</div>

I put above block into ng-repeat, not sure why the select contain 1 empty value as default value. When u selected something and click the dropdown again, it's gone.

Upvotes: 1

Views: 54

Answers (1)

dfsq
dfsq

Reputation: 193311

You need to provide an empty value attribute for an empty option tag if you want it to be preselected:

<select ng-model="data.fields.pax">
    <option value="">pax</option>
    <option value="1">1 pax</option>
    <option value="2">2 pax</option>
    <option value="3">3 pax</option>
    <option value="4">4 pax</option>
    <option value="5">5 pax</option>
    <option value="6">6 pax</option>
</select>

Demo: https://jsfiddle.net/9pvzf8kd/

Upvotes: 2

Related Questions