gpt4 book ai didi

javascript - AngularJS 中显示的 HTML 标签

转载 作者:太空宇宙 更新时间:2023-11-04 16:11:07 33 4
gpt4 key购买 nike

我有一个应用程序使用 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

DOCUMENTATION

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 包含到您的模块中。

关于javascript - AngularJS 中显示的 HTML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34880701/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com