2014-10-28 3 views
3

Angular 프로젝트에서 i18next (https://github.com/archer96/ng-i18next)를 사용하려고하는데로드가 너무 느립니다. 이것은 내 설정입니다.각도 모듈이로드 될 때까지 기다리는 방법은 무엇입니까?

angular.module('jm.i18next').config(['$i18nextProvider', function ($i18nextProvider) { 
    $i18nextProvider.options = { 
     lng: 'en', 
     fallbackLng: 'en', 
     preload: ['en'], 
     supportedLngs: ['en'], 
     resGetPath: '../locales/__lng__.json', 
     useCookie: false, 
     useLocalStorage: false, 
     defaultLoadingValue: '' 
    }; 
}]); 

angular.module('myApp', ['jm.i18next']).controller('MainCtrl', ['$scope', '$i18next', function ($scope, $i18next) { 
console.log($i18next("key")); 

setTimeout(function() { 
    console.log($i18next("key")); 
    }, 1000); 
}]); 

값을 사용하려면 시간 제한을 추가해야합니다. 컨트롤러가로드 될 때 i18next가 준비되었는지 확인하는 방법이 있습니까?


UPDATE

나는 $의 i18next를 사용하여 번역 유형에 의해 그룹 운동에 노력하고있어. 그러나 컨트롤러가 번역을 완료하기 전에 뷰가 "준비"상태이므로이 작업은 효과가 없습니다.

<select ng-model="workout" ng-options="workout as workout.name group by workout.type for workout in workouts | orderBy: ['type', 'name']"></select> 

$scope.workouts = [ 
    {id: 1, name: 'Workout 1', type: $i18next("type1")}, 
    {id: 25, name: 'Workout 2', type: $i18next("type2")}, 
    ]; 
+1

안녕하세요, 귀하의 컨트롤러가보기에 연결되어 있지 않습니까? 그렇다면 경로에서 모듈을로드 할 때까지 대기하라는 해결 방법을 사용할 수 있습니다. 하지만 일반적으로 각 모듈이 실행되기 전에로드 될 때까지 대기합니다 ... 모듈에 아약스 요청이 있습니까? –

+0

보기에 링크되어 있으며 선택 상자가 있습니다. 문제는 ng-options에 i18next 텍스트 목록이 포함되어 있고보기가 컨트롤러보다 "준비"상태 인 것 같습니다. 그게 의미가 있다면 :) 원본 게시물을 업데이트 할 것입니다. –

+1

경로에서 해결 방법을 추가하십시오. {i18next : function (YourModule) {YourModulePromise 돌아 가기}} –

답변

1

이 문제가 해결되었습니다.

angular.module('myApp', ['ngRoute', 'jm.i18next']). 
     config(['$routeProvider', function ($routeProvider) { 
      $routeProvider. 
       when('/route1', { 
        title: 'Route 1', 
        templateUrl: '../views/route1.html', 
        controller: 'Route1Ctrl', 
        resolve: { 
         i18next: function ($i18next) { 
         return $i18next; 
         } 
        } 
       }); 
    }]); 
+1

동일한 문제가 발생하여이를 수정했습니다. 비록 당신이 모든 경로에이 해결 기능을 넣어야만하기 때문에이 IMO는 추한 솔루션입니다 ... – karantan

0

당신은 또한 i18nextLanguageChange 이벤트를 수신 할 수 :

$scope.$on('i18nextLanguageChange', function() { 
    $scope.workouts = [ 
    {id: 1, name: 'Workout 1', type: $i18next("type1")}, 
    {id: 25, name: 'Workout 2', type: $i18next("type2")}, 
    ]; 
}); 

당신은 당신의 자신의 그런 식으로 다른 경쟁 조건을 해결해야합니다.