angular.js - angularjs處理/n轉(zhuǎn)<br/>時(shí)候 <br/>不會(huì)解析的問(wèn)題
問(wèn)題描述
<!DOCTYPE html><html ng-app><head lang='en'> <meta charset='UTF-8'> <title></title> <script src='http://www.aoyou183.cn/wenda/angular.min.js'></script> <script>function TextareaCtrl($scope){ var str='啦啦11范德薩范德薩nfadsfadsfadnfdfadfanfdafa'; $scope.name=str.replace(/n/g,'<br/>');} </script></head><body> <p ng-controller='TextareaCtrl'><p>{{name}}</p> </p></body></html>
結(jié)果:
啦啦11范德薩范德薩<br/>fadsfadsfad<br/>fdfadfa<br/>fdafa
問(wèn)題解答
回答1:要用到ng-bind-html
<!DOCTYPE html><html ng-app='test'><head lang='en'> <meta charset='UTF-8'> <title></title></head><body> <p ng-controller='TextareaCtrl'><p ng-bind-html='name'></p> </p> <script src='http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js'></script> <script> var myModule = angular.module('test',[]); myModule.controller('TextareaCtrl',['$scope','$sce',function($scope,$sce){ var str='啦啦11范德薩范德薩nfadsfadsfadnfdfadfanfdafa'; $scope.name=$sce.trustAsHtml(str.replace(/n/g,'<br/>')); }]); </script></body></html>回答2:
造成不解析的原因是angularjs對(duì)html進(jìn)行了過(guò)濾,把< > 符號(hào)變?yōu)?& l t; & g t;,有圖為證。我查了一下是可以禁用過(guò)濾器的,angularjs 實(shí)在不熟悉,幫不上你。
scope.Datas.userInfo.rich_summary=scope.Datas.userInfo.rich_summary.replace(/rn/gi,’<br/>’) scope.Datas.userInfo.rich_summary=scope.Datas.userInfo.rich_summary.replace(/r/gi,’<br/>’) scope.Datas.userInfo.rich_summary=scope.Datas.userInfo.rich_summary.replace(/n/gi,’<br/>’)
轉(zhuǎn)一下
相關(guān)文章:
1. javascript - 分類編輯保留之前分類名稱2. css - 移動(dòng)端 line-height安卓錯(cuò)位,蘋果機(jī)正常用,縮放解決了,可是又出來(lái)了占位的問(wèn)題3. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?4. javascript - 彈出一個(gè)子窗口,操作之后關(guān)閉,主窗口會(huì)得到相應(yīng)的響應(yīng),例如網(wǎng)站的某些登錄界面,django后臺(tái)的管理等,這是怎么實(shí)現(xiàn)的呢?5. javascript - 函數(shù)設(shè)置參數(shù)默認(rèn)值的問(wèn)題6. list - python 求助7. javascript 的console.log 問(wèn)題8. 環(huán)境搭建 - anaconda 創(chuàng)建python2.7環(huán)境中打開(kāi)編譯器確是3.6版本9. mysql replace 死鎖10. extra沒(méi)有加載出來(lái)
