簡體   English   中英

AngularJS:如何在控制器中使用翻譯(i18n)彈出窗口?

[英]AngularJS: How to use translation (i18n) in controller for popup?

我',在angularjs中編寫應用程序並且必須執行i18n。 一切都很好,但我做錯誤處理,有問題:我不知道如何在控制器中使用彈出窗口的翻譯。

我的控制器看起來像這樣:

function showErrorPopup($ionicPopup, $ionicHistory, $location, $translate, error) {
    if (error.status == 404) {
         errorId = ...

         $ionicPopup.show({
              title: '{{ERROR.TITLE | translate}}></span>',
              template: '{{ERROR.errorId| translate}}',
              buttons: [{ text: 'OK' }]
         });   
    }
    else if (error.data.ExceptionMessage != null || error.data.ExceptionMessage != "" || error.data.ExceptionMessage != undefined) {
        errorId = ...

        $ionicPopup.show({
              title: '{{ERROR.TITLE | translate}}></span>',
              template: '{{ERROR.errorId| translate}}',
              buttons: [{ text: 'OK' }]
         });   
    }
    else {
        errorId = ...

        $ionicPopup.show({
              title: '{{ERROR.TITLE | translate}}></span>',
              template: '{{ERROR.errorId| translate}}',
              buttons: [{ text: 'OK' }]
         });   
    }
}

這是我的控制器。 這取決於結果是什么,但我總是希望顯示一個錯誤的彈出窗口(錯誤的標題= ERROR.TITLE,錯誤的文本= ERROR.errorId)。

ERROR和他的TITLE或他的ID(如100,200 ......)在json文件中定義。

你能幫幫我解決這個問題嗎? 如果你必須了解更多,請問。

使用$translate服務

var translatedErrorTitle = $translate.instant(ERROR.TITLE);
var translatedErrorId    = $translate.instant(ERROR.errorId);

更多信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM