0

即時通訊目前採用了棱角分明實施與指令角SweetAlert和翻譯

Sweet alert

我想傳遞給冠軍的角度指令翻譯

這是我傳遞的變量標題

{{ 'register.confirmation_modal.SUPERIOR_MESSAGE' | translate }} 

而且使用Angular Compile Service

var translate_title = "<span>{{ 'sa.title' | translate }}</span>"; 
var compiled_title = $compile(translate_title)($scope); 

,並使用html: true,甜警報選項

但我發現了一個對象,它被印像後續的圖像

enter image description here

我使用.innerHTML嘗試,但它消除了標籤並使用大括號獲得文字字符串{{}}

JSON.stringify也沒有工作。

有什麼建議嗎?

+0

我不認爲這是處理控制器內部翻譯的正確方法。任何時候你必須使用'$ compile',它必須跟隨'$ rootScope。$ digest()'或'$ scope。$ apply()'的調用,並且通常從控制器調用這些是非常低效的。爲什麼不使用'$ filter('translate')('sa.title')'? – Claies

+0

Hi @Claies感謝您的反饋,它的工作!謝謝 – DannyG

回答

1

貸@Claies指着我的解​​決方案

而不是使用$compile我從使用的角度轉換Filter translate

這並獲得成功解決了我的問題:

var n = $filter('translate')('sa.title'); 

問候。