2017-12-07 4 views
0

改行文字/ nを含む文字列があります。表示しようとしています改行/ nを改行で改行します。

文字列です。/nを改行する代わりに、 '/ n'をテキストとして表示します。

$scope.myOutput = " Hello /n" 

    {{ myOutput | textFormat }} 

必須 - >こんにちは(上のHTMLページ)

が試み:

app.filter('textFormat', function() { 
    return function(x) { 
     return x.replace(/\\n/g, '<br/>'); 
    } 
ホワイトスペースのような

しようとしましたCSSスタイル:事前;

答えて

0

1 - あなたのフィルタを書き換える次の方法:

.filter('textFormat', function() { 
    return function (x) { 
     return x.replace(new RegExp('\/n', 'g'), '<br/>'); 
    } 
}) 

2 - あなたのhtmlであなたは次の構文を使用する必要があります:myOutput$scope.myOutput = ' Hello /n'

ある

<span ng-bind-html="myOutput | textFormat"></span>