user9
user9

Reputation: 39

html tags considered as plain text when using angular directives

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!

Upvotes: 0

Views: 191

Answers (2)

Kevin Boosten
Kevin Boosten

Reputation: 354

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

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

Upvotes: 1

aseferov
aseferov

Reputation: 6393

you need use ng-bind-html for this

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

Upvotes: 1

Related Questions