2017-07-08 37 views
1

當我嘗試發送HTML作爲參數在翻譯裝飾我的HTML代碼顯示爲文本,而不是HTML。像代碼下:發送Html作爲參數在翻譯裝飾在angularjs

<!doctype html> 
<html ng-app="myApp"> 
    <head> 
<script src="https://cdn.rawgit.com/SlexAxton/messageformat.js/v1.0.2/messageformat.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-animate.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-cookies.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular-sanitize.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.15.2/angular-translate.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-interpolation-messageformat/2.15.2/angular-translate-interpolation-messageformat.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-storage-cookie/2.15.2/angular-translate-storage-cookie.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-storage-local/2.15.2/angular-translate-storage-local.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-loader-url/2.15.2/angular-translate-loader-url.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-loader-static-files/2.15.2/angular-translate-loader-static-files.js"></script> 
<script src="https://cdn.rawgit.com/angular-translate/bower-angular-translate-handler-log/2.15.2/angular-translate-handler-log.js"></script> 
<script src="script.js"></script> 
</head> 
    <body> 

<div ng-controller="Ctrl"> 
    <p>{{ 'HEADLINE' | translate }}</p> 
    <p>{{ 'PARAGRAPH' | translate }}</p> 
</div> 


    </body> 

​​

結果我得到:

This is cool link <a href="http://google.com">test</a> Check it out! 

HTML代碼,它自身的瀏覽器,而不是錨HTML表示。 我想要錨點作爲html標籤進行處理。

有人有建議嗎?

+0

替換<與<和>與> –

回答

0

爲了實際處理HTML而不是將其輸出爲字符,可以使用ng-bind-html指令。在你的情況下,它看起來就像這樣:

<p ng-bind-html="'PARAGRAPH' | translate"></p> 
+0

NG綁定,HTML指令解決我的問題!謝謝。 – Michael2000

+0

@ Michael2000沒問題。不要忘記接受我的答案。 –