0

I have an ng-repeat in a select menu:

<label>Country</label>
    <select name="seller-country" class="form-control input-sm">
      <option ng-repeat="c in countries | orderBy:predicate" value="{{c.code}}">{{c.code}} ({{c.name}}) </option>
    </select>

The first item in the data is empty, as in

{
  "countries": [{
     "name": "",
     "code": ""
     }, ...

I set up the binding above so the menu items will read as in CA (Canada), so for the empty string it reads (). I'd like to not show the parens for the empty string.

UPDATE The answer below is indeed correct, but in this case I was the one who added the empty first item in a misguided attempt to get an empty select item before checking the Angular docs for select. It seems you can do exactly what I was trying to do by simply adding an extra first option item:

<select name="seller-country" class="form-control input-sm">
      <option value="">Choose...</option>
      <option ng-repeat="c in countries | orderBy:predicate" value="{{c.code}}">{{c.code}} ({{c.name}}) </option>
    </select>

1 Answer 1

1
  <option ng-repeat="c in countries | orderBy:predicate"
     ng-if="c.code != '' && c.name!= '' && c.code != null && c.name!= null" 
     value="{{c.code}}">{{c.code}} ({{c.name}}) </option>
Sign up to request clarification or add additional context in comments.

Comments

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.