[英]Wordpress Rest API and AngularJS ui-sref and custom HTML
我正在設置一個AngularJS應用,以使用wp-rest api v2從Wordpress后端提取其某些內容。
它運作良好,但是如果我的帖子輸入了這樣的HTML,則某些HTML屬性將被明顯剝奪
I have a <a ui-sref="trays">link</a>
我的角度應用程序中的結果頁面沒有ui-sref,僅
<p>I have a <a>link</a></p>
我也嘗試過
I have a <a href= "" ui-sref="trays">link</a>
但后來我只得到
<p>I have a <a href="">link</a></p>
我不希望Wordpress能“理解” ui-sref
功能,但是我如何才能將代碼傳遞給我的應用程序,該應用程序確實知道如何處理此類鏈接。
我如何從后端獲取所有html到Angular?
在模板上,我有
<div ng-bind-html="post.content.rendered"></div>
在郵遞員中,查詢帖子時我得到了:
"content": {
"rendered": "<p>hello there I am <strong>another</strong> post!</p>\n<p>I have a <a href= \"\" ui-sref=\"trays\">link</a>, too.</p>\n",
"protected": false
},
我嘗試將過濾器添加到ng-bind-html
以信任文本:
<div ng-bind-html="post.content.rendered | toTrusted"></div>
使用這個過濾器
angular.module('app').filter('toTrusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}]);
確實通過ui-sref。 但是,除非我也添加一個空的href
,否則該鏈接不會注冊為鏈接,但是它僅適用於我的默認路由,而不是“托盤”。
當ui-router找不到此路由時,會發生這種情況,請檢查是否包含托盤路由以及所有文件,並嘗試訪問沒有鏈接的路由,將路由URL放在瀏覽器中,並顯示該URL是否存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.