Javascript 在ng repeat中从JSON解析HTML
我今天开始学习AngularJS,到目前为止我做得很好。但我遇到了一个问题,似乎找不到答案。我试图做的是将html字符串Javascript 在ng repeat中从JSON解析HTML,javascript,json,angularjs,Javascript,Json,Angularjs,我今天开始学习AngularJS,到目前为止我做得很好。但我遇到了一个问题,似乎找不到答案。我试图做的是将html字符串文本打印为格式化的文本。到目前为止,Angular将其打印为纯文本 我的代码如下: JS HTML {{post.content} 我的问题是{{post.content}。我想尝试ng bind unsafe,但它已被删除。我还尝试了ngbindhtml=“post.content”,但没有成功 我使用的是Angular 1.4。您正在寻找的。例如,对于您的内容,您可以
文本打印为格式化的文本。到目前为止,Angular将其打印为纯文本
我的代码如下:
JS
HTML
{{post.content}
我的问题是{{post.content}
。我想尝试ng bind unsafe
,但它已被删除。我还尝试了ngbindhtml=“post.content”
,但没有成功
我使用的是Angular 1.4。您正在寻找的。例如,对于您的内容,您可以使用以下内容:
<div ng-bind-html="post.content"></div>
计算表达式并以安全的方式将结果HTML插入元素中。默认情况下,生成的HTML内容将使用$sanitize服务进行清理。要利用此功能,请确保$sanitize可用,例如,通过在模块的依赖项(而不是核心依赖项)中包含ngSanitize。为了在模块的依赖项中使用ngSanitize,您需要在应用程序中包含“angular sanitize.js”
恐怕不行。正如我在问题中所说,我尝试过使用它,但它不起作用。新手的错误是,我没有包括ngSanitize
(如我的代码所示);-)现在可以工作了,谢谢!
<article id="post-{{post.ID}}" <?php post_class(); ?> itemscope itemprop="blogPost" itemtype="http://schema.org/BlogPosting" ng-repeat="post in posts" ng-class="postsLoaded">
<h2 class="entry-title" itemprop="headline"><a title="Link do {{post.title}}" rel="bookmark" href="{{post.link}}">{{post.title}}</a></h2>
<div class="entry-content">
<img ng-src="{{post.featured_image.source}}">
{{post.content}}
</div>
<footer class="entry-footer">
<ul class="categories"><li ng-repeat="category in post.terms.category"><a href="{{category.link}}">{{category.name}}</a></li></ul>
</footer>
</article>
<div ng-bind-html="post.content"></div>