限制ng-bind-html Angular JS中字符的简单方法 [英] Simple way to limit characters in ng-bind-html Angular JS

查看:48
本文介绍了限制ng-bind-html Angular JS中字符的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图限制我在我的angular js应用程序中看到的字符.目前我正在使用:

I am trying to limit the characters i see on my angular js app. Currently i am using:

<p ng-bind-html="item.get('Content') | limitTo: 150"></p>  

但是没有喜悦,没有任何想法...

But no joy, any ideas...

推荐答案

我认为这不适用于ng-bind-html.这是用于将实际的html代码绑定到页面. ng-bind应该可以正常工作.

I don't think that will work with ng-bind-html. This is for binding actual html code to the page. ng-bind should work fine.

<p ng-bind="item.get('Content') | limitTo: 150"></p>  

请参阅plunkr http://plnkr.co/edit/y0LXMMFi6sU9AhShvuha?p=preview

See plunkr http://plnkr.co/edit/y0LXMMFi6sU9AhShvuha?p=preview

由于其中确实包含HTML代码,因此需要使用ngSanitize.您可以在此处阅读有关内容: https://docs.angularjs.org/api/ngSanitize

Since you do have HTML code in it, you'll need to use ngSanitize. You can read about that here: https://docs.angularjs.org/api/ngSanitize

将引用添加到angular-sanitize.js,然后将其导入到应用程序中

Add the reference to angular-sanitize.js, then import it into the app

var app = angular.module('plunker', ['ngSanitize']);

然后,您的原始代码应该可以正常工作,尽管它的某些部分可能会被截断,包括结尾标记,因此您需要进行处理.

Then your original code should work fine, although it's likely parts of it will be cut off, including ending tags, so you'll need to deal with that.

请参阅plnkr: http://plnkr.co/edit/y0LXMMFi6sU9AhShvuha?p=preview

这篇关于限制ng-bind-html Angular JS中字符的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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