0

for example:

function foo() located in my controller:

              $scope.getOffers = function(){
                 var txt1="aaaa"+"<br>"+"bbbb";
                  $scope.newData = txt1;
              };

and my html:

                <div class="help-block" ng-show="newData ">{{ offers }}</div> 

and when I called foo() the text that showed up was: aaaa<br>bbbb instead of :

        aaaa
        bbbb

(I already tried to insert \n in my text...) What am I missing? and how can I fix the problem?

thanks!

2
  • you can use helpers like .trustAsHtml() or ng-bind-html to help with this, but if you are trying to structure your variables to hold HTML in the first place, you are probably not fully embracing the angular paradigm. Commented Apr 25, 2016 at 11:06
  • try with ng-bind-html-unsafe, you can check this fiddle jsfiddle.net/VFVMv Commented Apr 25, 2016 at 11:08

2 Answers 2

1

And don't forget to trust the html. https://docs.angularjs.org/api/ng/service/$sce

See this plunker http://embed.plnkr.co/HAKJ2iknZeeEOsgukoGd/

Sign up to request clarification or add additional context in comments.

1 Comment

thanks! the combinition of the 2 answers is perfect! Can you please tell me what is ` $sce`?
1

you need use ng-bind-html for this

 <div class="help-block" ng-show="newData " ng-bind-html="offers"></div> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.