Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default picker choice? #42

Open
maeishoj opened this issue Jul 22, 2015 · 1 comment
Open

Default picker choice? #42

maeishoj opened this issue Jul 22, 2015 · 1 comment

Comments

@maeishoj
Copy link

Hi there.

I am using this and I am very happy with it.

However I am not sure how to go about selecting the default choice for the picker...

Currently i do this:

<select class="m-l-20 pull-right selectpicker" selectpicker ng-model="currentLanguage">
    <option ng-repeat="language in defaultLanguage" data-content="<span class=''><img src='/assets/img/flags/{{language.Value}}.png'/> {{language.Name}}</span>" value="{{language}}"> </option>

    <option ng-repeat="language in campaign.Languages" data-content="<span class=''><img src='/assets/img/flags/{{language.Value}}.png'/> {{language.Name}}</span>" value="{{language}}"> </option>
</select>

But it seems a very nasty way of doing it.. Basically I have my Languages as objects in an array (campaign.Languages) but in order to have the first language selected by default I have to add the first and do ng-repeat on an array with 1 single item which i initialize it to be the first language of the main language array.

There must be a better way of doing this..

@madmoizo
Copy link

madmoizo commented Aug 7, 2015

yes, it's nasty :)

basic example :

<select selectpicker 
     ng-model=".currentLanguage" 
     ng-options="language.value as language.label for language in languages track by language.value">
</select>

if language.value = ng-model, it will be selected

with somethin like this in your controller (coffeescript syntax)

languages = [
  {
      value: "fr"
      label: "<img src='/assets/img/flags/fr.png'/> French"
  }
  {
      value: "en"
      label: "<img src='/assets/img/flags/en.png'/> English"
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants