0

I have a similar question as these ones :

How to ng-translate inside select box option in angularjs

angular-translate ad ng-options

But my case is a bit different. I would like that my ng-option fill up automatically with elements from a list in my json. And I would like to avoid defining these elements in my controller (because otherwise each time an element is added to the list I will need to add them in my controller manually).

Here is the concerned part in my .json :

 "availLanguages" : [
   "Deutsch",
   "English",
   "Français"
  ],

My controller's instance is called "language". So I've tried the followings :

 <select ng-options="language for languages in 'availLanguages' | translate" ng-model="language.selectedLanguage" ng-change="language.changeLanguage()"></select>

Thanks,

EDIT: here's the result :

enter image description here

Each object is a letter from "availLanguages".

Community
  • 1
  • 1
Cassifiore
  • 89
  • 1
  • 10

1 Answers1

0

You haven't passed the value of ng-model to you scope function. try this. this might help you. console selected language in function.

<select ng-options="language in 'availLanguages' | translate" ng-model="language.selectedLanguage" ng-change="language.changeLanguage(language.selectedLanguage)"></select>
Himesh Suthar
  • 562
  • 4
  • 14
  • Well I've mocked this function so that the testing is easier. For now this function only swap between two set values. but my ng-options doesn't work because my drop down list is empty. – Cassifiore Oct 04 '16 at 11:53
  • Provide a plunkr, codepen or jsfiddle and I might be able to help – AllJs Oct 04 '16 at 12:11