2

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

任何帮助将非常感激,

谢谢!

4

1 回答 1

3

您需要使用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到您的模块中。

于 2016-01-19T15:40:16.907 回答