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!
您需要为此使用ng-bind-html
<div class="help-block" ng-show="newData " ng-bind-html="offers"></div>
And don't forget to trust the html. https://docs.angularjs.org/api/ng/service/$sce
See this plunker http://embed.plnkr.co/HAKJ2iknZeeEOsgukoGd/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.