2017-12-07 27 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>