Reputation: 55
I am using angular translator in my app translation is working with the labels how to do add a translation to the dependent dropdown.Dropdown data is in the form of JSON how to write it in a config function
Controller
.controller('vendorCtrl', function($scope,$translate) {
$scope.Districts =[
{
'id': '1',
'name': "Haveri",
'Talukas': [{
'id': '71',
'dep': "Bydagi"
}, {
'id': '72',
'dep': "Rannebennur"
},
{ 'id': '73',
'dep': "Hirrekerur"
},{
'id': '74',
'dep': "Shiggaon"
},
{ 'id': '75',
'dep': "Hangal"
},{ 'id': '76',
'dep': "Savanur"
}]
},
{
'id': '8',
'name': "Koppal",
'Talukas': [{
'id': '81',
'dep': "Gangavathi"
}, {
'id': '82',
'dep': "Kushtagi"
},
{ 'id': '83',
'dep': "Yelbarga"
}]
}, {
'id': '9',
'name': "Vijapur",
'Talukas': [{
'id': '91',
'dep': "Indi"
}, {
'id': '92',
'dep': "Muddebihal"
},
{ 'id': '93',
'dep': "Sindgi"
} , {
'id': '94',
'dep': "BasavanBagewadi"
}]
}
];
Html
<select id="District" ng-model="selectedDistrict" ng-options="District.id as District.name for District in Districts track by District.id">
<option value="">Select</option>
</select>
<select id="Taluka"
ng-model="selectedTaluka"
ng-disabled="!selectedDistrict"
ng-model="selectedTaluka"
ng-options="Taluka.id as Taluka.dep for Taluka in ((Districts | filter:{'id':selectedDistrict})[0].Talukas) track by Taluka.id">
<option value="">Select</option>
</select>
Upvotes: 0
Views: 103
Reputation: 36
I assume you use angular-translate and try to translate the district names. Then you can use the translate pipe in ng-options. Try ng-options="District.id as District.name | translate for District in Districts track by District.id"
Upvotes: 1