angularjs newline filter with no other html

后端 未结 7 1060
北恋
北恋 2020-12-07 14:14

I\'m trying to convert newline characters (\\n) to html br\'s.
As per this discussion in the Google Group, here\'s what I\'ve got:



        
7条回答
  •  一生所求
    2020-12-07 14:34

    Instead of messing with new directives, I decided to just use 2 filters:

    App.filter('newlines', function () {
        return function(text) {
            return text.replace(/\n/g, '
    '); } }) .filter('noHTML', function () { return function(text) { return text .replace(/&/g, '&') .replace(/>/g, '>') .replace(/

    Then, in my view, I pipe one into the other:

    
    

提交回复
热议问题