AngularJS - Remove \n from data

后端 未结 6 1416
醉梦人生
醉梦人生 2021-02-07 19:52

What is the best way to catch and format the \"\\n\\n\" inside of text being passed from the server to display line breaks? Fiddle is here: http://jsfiddle.net/nicktest2222/2vYB

6条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 20:25

    Angular 1.2 removed ng-bind-html-unsafe so here's an updated solution.

    The HTML:

    And the JS:

    .filter('nl2br', function ($sce) {
        return function (text) {
            return text ? $sce.trustAsHtml(text.replace(/\n/g, '
    ')) : ''; }; })

提交回复
热议问题