【发布时间】:2016-05-11 17:32:15
【问题描述】:
在 AngularJS 中解析 JSON 时如何提取某些标签,例如 img? 我有一个包含以下数据的 JSON 文件:
jsonFeed({
"title": "My Blog",
"items": [
{
"title": "Title1",
"description": "<p><a href=\"#">Paul<\/a> posted a photo:<\/p><img src=\"https://farm8.staticflickr.com/7365/26872407641_cfbb210ee7_m.jpg\"/>"
},
{
"title": "Title2",
"description": "<p><a href=\"#">Beth<\/a> posted a photo:<\/p><img src=\"https://farm8.staticflickr.com/7287/26333398074_cfbce73532_m.jpg\"/>"
}
]
});
我需要在每个帖子的描述中获取该图像:
<article ng-repeat="post in posts">
<h1>{{ post.title }}</h1>
<img src=""/>
</article>
有没有办法在 angularjs 中做到这一点,还是使用 jQuery 更好?
【问题讨论】:
-
使用 substring 和 indexof 方法从描述中获取 img 标签。使用角度 $sanitize 显示 html
标签: javascript jquery angularjs json