156
rated 0 times
[
158]
[
2]
/ answers: 1 / hits: 40170
/ 9 Years ago, tue, june 30, 2015, 12:00:00
I want a dropdown list to change the language my site is displayed in, so I currently have:
<select ng-controller=langCtrl>
<option ng-click=switchLanguage('en') value=en>EN</option>
<option ng-click=switchLanguage('de') value=de>DE</option>
<option ng-click=switchLanguage('it') value=it>IT</option>
<option ng-click=switchLanguage('fr') value=fr>FR</option>
<option ng-click=switchLanguage('es') value=es>ES</option>
</select>
However for some reasons these ng-click
s don't seem to be calling the specified function. I changed them all to buttons, and that seemed to work fine, but I want a dropdown list, not buttons. Can anyone tell me why this doesn't work?
Controller code:
app.controller('langCtrl', function($translate, $location, $scope) {
$scope.switchLanguage = function (langKey) {
switch(langKey) {
case 'en':
$location.url('/#en');
break;
case 'de':
$location.url('/#de');
break;
case 'it':
$location.url('/#it');
break;
case 'fr':
$location.url('/#fr');
break;
case 'es':
$location.url('/#es');
break;
default:
$location.url('/#en');
}
$translate.use(langKey);
};
});
More From » html