Simple way to limit characters in ng-bind-html Angular JS

前端 未结 8 752
自闭症患者
自闭症患者 2021-01-13 02:15

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

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-13 02:28

    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.

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

    EDIT:

    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

    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.

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

提交回复
热议问题