我有一个ngSelect,里面有一些选项.
<select data-ng-model="type" data-ng-change="option(type)"> <option data-ng-repeat="type in languages" value="{{type.i18n}}"> {{type.language}} </option> </select>
还有一个控制器
angular.module('navigation',[]) .controller('NavCtrl',['$scope','$translate',function($scope,$translate){ $scope.option = function(type){ console.log(type) //this display the i18n value of languages $translate.use(type); } $scope.languages = [ { language: "English",i18n: "en_EN"},{ language: "Swedish",i18n : "se_SE" } ]; }])
我希望ngSelect有一个默认选项,在我的情况下:“英语”.我试着把它设置为:
$scope.type = $scope.languages[0].language; // English $scope.type = $scope.languages[0]; //The whole darn json object.
请帮忙?
试试这种方式
<select ng-model="selectedlanguage" ng-change="option(this.selectedlanguage)" ng-options="i.language for i in languages"> </select>
// Js代码
angular.module('navigation',i18n : "se_SE" } ]; **$scope.selectedlanguage = $scope.languages[0];** }])