在 AngularJS 中显示的 HTML 标记
HTML tags showing in AngularJS
我有一个应用程序,它使用Wordpress插件WP-API从另一个站点提取数据。
我正在起诉 AngularJS然后显示此信息,我真的是 AngularJS 的新手,所以我的问题是从帖子中提取了正确的信息,但显示了 HTML 标签,例如 <p>text</p>
.
我正在提取这样的数据(我的代码片段)-
<script>
var app = angular.module('myApp', []);
app.controller('aLlCtrl', function($scope, $http) {
var url = 'http://scd.blaze.wpengine.com/wp-json/posts?type=listings&filter[listing_area]=channel';
$http.get(url).then(function(data) {
$scope.data = data.data;
});
});
</script>
<body ng-app="myApp">
<!--SHOOTING TYPE-->
<div id="All" class="descshoot">
<div ng-controller="aLlCtrl">
<div ng-repeat="d in data">
<h2 class="entry-title title-post">{{d.title}}</h2>
<div id="listing-image"><img src="{{d.acf.logo}}"></div>
<div id="listing-contact">Contact: {{d.acf.contact}}, {{d.acf.position}}</div>
<div id="listing-address-1">
{{d.acf.address_1}}, {{d.acf.address_2}} {{d.acf.address_3}} {{d.acf.town}} {{d.acf.county}} {{d.acf.postcode}}
</div>
<div id="listing-phone">Telephone: {{d.acf.telephone}}</div>
<div id="listing-mobile">Mobile: {{d.acf.mobile}}</div>
<div id="listing-email">Email: {{d.acf.email}}</div>
<div id="listing-website">Website: <a href="{{d.acf.website}}">{{d.acf.website}}</a></div>
<div id="listing-established">Established: {{d.acf.established}}</div>
<div id="listing-about">About: {{d.acf.about}}</div>
<div id="listing-mailingaddress">Mailing Address: {{d.acf.mailing_address_}}, {{d.acf.mailing_address_2}}, {{d.acf.mailing_address_3}}, {{d.acf.mailing_town}}, {{d.acf.mailing_county}}, {{d.acf.mailing_postcode}}</div>
<div id="listing-directions">Directions: {{d.acf.directions}}</div>
<div id="scd-link"><a href="{{d.link}}">View on The Shooting Club Directory</a></div>
</div>
</div>
</div>
</body>
这是我的代码的(非工作)笔 - http://codepen.io/anon/pen/yePYdq 和它工作的站点 http://dev.5874.co.uk/goshooting/regions/channel-islands/
任何帮助将不胜感激,
谢谢!
你需要使用ng-bind-html
属性:JSFiddle
文档
.HTML:
<div ng-app="myApp" ng-controller="myCtrl">
{{test}} <!--will show '<p>test</p>'-->
<div ng-bind="test"></div> <!--will show '<p>test</p>'-->
<div ng-bind-html="test"></div> <!--will show 'test'-->
</div>
.JS:
angular.module("myApp", ["ngSanitize"])
.controller("myCtrl", function($scope) {
$scope.test = "<p>test</p>";
});
注意:不要忘记将ngSanitize
包含在模块中。
相关文章:
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- HTML标记在脚本标记中工作
- 是否可以添加这行“;“照原样”;在HTML标记中
- 一个正则表达式,用于从JS中的HTML标记中删除id、样式和类属性
- 如果匹配项在特定的html标记中,则跳过regex匹配
- 使用 Pure JS 更改 HTML 标记名称
- 如何使用javascript选择字符串的部分,添加html标记或删除部分
- HTML标记,包含带引号的JavaScript代码中的引号
- 如何在JavaScript中创建打字机效果,这将考虑html标记规则
- 将c#视图模型转换为javascript模型时转义HTML标记
- Regex剥离具有特定属性的html标记
- 如何在不创建格式错误的HTML标记的情况下分解字符串
- HTML 标记未在 AngularJS ckEditor 中应用,而是在 Ediator 中显示 HTML 元素标记代码
- 如何在angularJS中运行for循环而不使用html标记
- Riot 每个构建 HTML 标记
- 用HTML标记+ 替换关闭的HTML标记
- 存储包含html标记的文本
- Regex以转义HTML标记
- 在html标记中序列化javascript代码
- JS来显示HTML标记