[英]Wordpress Rest API and AngularJS ui-sref and custom HTML
I am setting up an AngularJS app to pull some of its content from a Wordpress back-end using the wp-rest api v2. 我正在设置一个AngularJS应用,以使用wp-rest api v2从Wordpress后端提取其某些内容。
It's working well, but certain HTML attributes are being stripped out notably if my post has HTML entered like this 它运作良好,但是如果我的帖子输入了这样的HTML,则某些HTML属性将被明显剥夺
I have a <a ui-sref="trays">link</a>
The resulting page in my angular app does not have the ui-sref, and is only 我的角度应用程序中的结果页面没有ui-sref,仅
<p>I have a <a>link</a></p>
I have also tried 我也尝试过
I have a <a href= "" ui-sref="trays">link</a>
but then I only get 但后来我只得到
<p>I have a <a href="">link</a></p>
I don't expect Wordpress to "understand" what ui-sref
does, but how can I get the code to pass through to my app, which does understand what to do with such a link. 我不希望Wordpress能“理解”
ui-sref
功能,但是我如何才能将代码传递给我的应用程序,该应用程序确实知道如何处理此类链接。
How do I get all the html from the back end to come through to Angular? 我如何从后端获取所有html到Angular?
On the template, I have 在模板上,我有
<div ng-bind-html="post.content.rendered"></div>
in Postman, when querying the post I get back: 在邮递员中,查询帖子时我得到了:
"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
},
I have tried adding a filter to the ng-bind-html
to trust the text: 我尝试将过滤器添加到
ng-bind-html
以信任文本:
<div ng-bind-html="post.content.rendered | toTrusted"></div>
which is using this filter 使用这个过滤器
angular.module('app').filter('toTrusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
};
}]); }]);
Which does pass through the ui-sref. 确实通过ui-sref。 However, the link does not register as a link unless I also add an empty
href
, but then it just does to my default route, not "trays". 但是,除非我也添加一个空的
href
,否则该链接不会注册为链接,但是它仅适用于我的默认路由,而不是“托盘”。
当ui-router找不到此路由时,会发生这种情况,请检查是否包含托盘路由以及所有文件,并尝试访问没有链接的路由,将路由URL放在浏览器中,并显示该URL是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.