angular-translate は HTML の変更に取り組んでいます。変更する必要がある ngDropdown ボタン ディレクティブの選択項目の配列があります。言語を変更した後、translate.use() を使用して新しい/現在の言語を取得しようとします。何かがうまくいきません。
ここにHTMLがあります
<div id="postBox" class="floatingSection" data-ng-controller="postButtonController2">
<button id="postButton" dropdown-menu="ddMenuOptions" dropdown-model="ddMenuSelected" class="btn-menu" ng-click="getCurrentLanguage()">{{ 'POST' | translate }}</button>
</div>
これがその postButton のコントローラーです。$translate から新しい/現在の言語を取得し、その文字列を使用してドロップダウン選択配列を取得する必要があります。ddSelections.withLangChoice $scope.getCurrentLanguage は、ハードコードされている場合は正しい配列を選択しますが、言語文字列の $translate から変数を取得する場合は選択しません。
ドロップダウン付きのボタンのコントローラーを次に示します。コメントは、機能するものと機能しないものを数行にわたって説明します。
residenceApp.controller('postButtonController2', ['$translate', '$scope', 'changePostDdFactory',
function ( $translate, $scope, ddSelections ){
//ddSelections is the result object from the function returned by changePostDdFactory
$scope.getCurrentLanguage = function( $translate ){
alert('here I am in postButtonController2'); //fires on post button clicks and on page load
alert('here I am in postButtonController2' + $translate.use()); //does not fire on post button clicks. fires on page load
$scope.langKey=$translate.use(); //gets langKey in $translate on page load only
$translate.refresh($scope.langKey);//should refresh the translation, but nothing
alert('from postButtonController2 - currentLanguage is' + ' ' + $translate.use() ); //does not fire on button click. fires on page load
//return 'es'; //hardcoded works on page load & sets ddSelections.withLangChoice to es array
return $translate.use(); //sets language for ddSelections on page load, no language changes
};
$scope.ddMenuOptions = ddSelections.withLangChoice($scope.getCurrentLanguage($translate)); //works on page load, no language change occurs
$scope.ddMenuSelected = {};
//working code to watch for change from user selection
}]);
私は新しいのですが、コントローラーで $translate サービスが動作するべきではありません。それが本当であると仮定すると、変更を行うには何を変更する必要があります。最近、ボタンの HTML に ng-click を追加しましたが、それ自体には何の影響もありませんでした。