AngularJS - Remove \n from data

后端 未结 6 1413
醉梦人生
醉梦人生 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:33

    If 'text' is null it returns an error, I added:

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

提交回复
热议问题