2014-10-09 51 views
0

您好,角返回HTML元素

所以我用AngularJS作爲前端框架和WordPress作爲後端實驗。我使用了JSON wordpress插件,並通過Angular中的$ http請求加載內容。

內容是一個字符串,我想從中提取一些圖像。我試圖做這樣的:

BlogPost.prototype.images = function() 
{ 
    var element = document.createElement('div'); 
    element.innerHTML = this._data; 

    var imgs = element.getElementsByTagName('img'); 
    var array = [].slice.call(imgs); 

    return array; 
} 

而且我的html:

<div class="media"> 
    <p class="img" ng-repeat="imgs in post.images()" ng-bind-html="imgs"> 
</div> 

它不工作,我的我的HTML頁面上輸出的輸出爲:[對象HTMLImageElement]和在控制檯中出現以下錯誤:https://docs.angularjs.org/error/ $ rootScope/infdig(錯誤:錯誤:infdig無限$ digestLoop)是否有另一種方法從字符串中獲取一些html元素並將它們返回給我的角模板?

在此先感謝。

回答

0

我正在寫一個Angularjs這裏WordPress的前端項目的GitHub代碼: https://github.com/altrovideo/wordpress-angularjs

我已經解決了使用您的問題https://wordpress.org/plugins/json-rest-api/ 和驗證碼:

<table class="table table-hover"> 

    <tbody> 
    <tr ng-repeat="post in filteredArticoli"> 
     <td ng-bind-html="post.title"></td> 
     <td><a ng-href="{{post.featured_image.source}}"><img ng-src="{{post.featured_image.attachment_meta.sizes.thumbnail.url}}"></a></td> 
     <td ng-bind-html="post.excerpt"></td> 

    </tr> 
    </tbody> 
</table>