Angularjs:NG绑定,HTML和放大器; NG-重复 [英] Angularjs: ng-bind-html & ng-repeat

查看:195
本文介绍了Angularjs:NG绑定,HTML和放大器; NG-重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我更新后,我找回它们从数据库中该模板的观点:

I have a views that i am updating after I retrieve them from the database for this template:

<div class="row" ng-repeat="post in posts">
        <div class="col-lg-9 col-lg-offset-2">        
          <!-- blog entry -->
          <br ng-hide="$last">
          <h1><a href="{{'#/post/' + post.title}}">{{post.title}} </a></h1>
          <p><span class="glyphicon glyphicon-time"></span> Posted on {{ post.time_Date | date:'MM/dd/yyyy @ h:mma'}} </p>
          <div class="image_Center">
            <!-- <img ng-src="{{post.imageUrl}}" width="550" height="450"> -->
            <img ng-src="{{post.imageUrl}}" width="450" height="350">
          </div>
          <br>
          <br>
          <div ng-bind-html="TrustDangerousSnippet()">
            <p>{{post.post}}</p>
          </div>
............not properly closed(huge template)

我试图更新{{post.post}}与我店,并让它正确显示使用我的控制器降价文本。在code是如下:

I am trying to update {{post.post}} with markdown text that I store and have it display properly using my controller. The code is as follows:

$scope.posts = input_data;
$scope.TrustDangerousSnippet = function() {
  return $sce.trustAsHtml(input_data.post);
};      

input_data是从我的服务器的JSON对象(博客文章)的集合。问题是,不显示此整个对象,但是,如果是要显示的对象之一,它呈现到页。可能是什么问题?

input_data is the collection of JSON objects(blog posts) from my server. The problem is that this entire object is not displayed, but if were to display one of the objects, it renders to the page. What could be the problem?

$scope.posts = input_data;
$scope.TrustDangerousSnippet = function() {
  return $sce.trustAsHtml(input_data[1].post);
};      

这是否有东西做以适当的方式不使用NG-重复?

Does this have something to do with not using ng-repeat in a proper way?

推荐答案

您想在TrustDangerousSnippet功能input_data.post分析,但是,这并不存在。

Your trying to parse input_data.post in the TrustDangerousSnippet function, but that doesnt exist.

相反,传递对象到像这样的方法:

Instead, pass the object into the method like this:

<div ng-bind-html="TrustDangerousSnippet(post.post)">
</div>

方法更改为:

$scope.TrustDangerousSnippet = function(snippet) {
  return $sce.trustAsHtml(snippet);
};  

小提琴例如: http://jsfiddle.net/ZxPHW/

编辑:此外,你并不需要添加{{post.post}}的HTML

in addition, you don't need to add {{post.post}} to the html.

这篇关于Angularjs:NG绑定,HTML和放大器; NG-重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆