0

I'm trying to initialize data in combobox, and I have tried every possible ways, but nothing:

<select ng-init= "account.username = githubaccounts[0].username" data-ng-model="account" data-ng-options="account.username for account in githubaccounts"
                    class="btn btn-default" data-container="body">

            </select>

<div class="form-group" ng-show="account.username == 'Other'">
            <label for="groupNameTxt">Group Name:</label>
            <input type="text" class="form-control" name="groupNameTxt" id="groupNameTxt" placeholder="Enter Group Name..." ng-model="group.groupName">
          </div>

Other way that it works is this:

<select class="btn btn-default" data-container="body"
          ng-init="githubaccounts[0].username" ng-model="account">
        <option ng-repeat="account in githubaccounts" value="">
                    {{account.username}}
        </option>
</select>

But, then, ng-show doesn't work:

Any ideas? Thank you very much.

Izaskun Peña
  • 177
  • 2
  • 4
  • 14

1 Answers1

0

Make following changes in code

<select ng-init= "anyModelVariable.username = githubaccounts[0].username" data-ng-model="anyModelVariable.username " data-ng-options="account.username for account in githubaccounts"
class="btn btn-default" data-container="body">
</select>

Changes: 1. use different variable in ng-model other then account.

  1. initialize same variable ng-model with with githubaccounts[0].username.
rahulgarg
  • 330
  • 3
  • 9