簡體   English   中英

如何格式化HTML中存儲的數據

[英]How to format stored data in html

我有如下數據,我想顯示的是根據模板中格式的數據。 我的數據

[ 

{
    "_id" : ObjectId("587daf9604a192098ac39fe1"),
    "uuid" : "3a06d55e-b2b0-4e24-9c17-fdf96a3827e6",
    "active" : true,
    "created" : ISODate("2017-01-17T05:45:58.919Z"),
    "description" : "khsjq<br />wsjqwsqw<br />wwsnqwksqwsws"
}, 
{
    "_id" : ObjectId("587db2f404a192098ac39fe3"),
    "uuid" : "454a1ff2-d64d-48d6-bb01-b3bc814aca01",
    "active" : true,
    "created" : ISODate("2017-01-17T06:00:20.439Z"),
    "description" : "iifdjasda<br />dlsldsad<br />asd<br />sadsadasdasdsadsadsad"
}]

我的js

   $.each(vm.courseObj.course_module, function (i, v) {
          v.description = $sce.trustAsHtml(v.description);
          vm.courseModulearr.push(v);
      });

不幸的是,它沒有反映在我看來,顯示為iifdjasda
dlsldsad
阿斯
我認為sadsadasdasdsadsadsad。誰能幫我。謝謝。

創建一個這樣的trust過濾器

.filter('trust', [
    '$sce',
    function($sce) {
      return function(value, type) {
        return $sce.trustAs(type || 'html', value);
      }
    }
  ]);

並像這樣綁定值

<div ng-bind-html="htmlData | trust"></div>

查看我的工作小提琴

你可以看看我的朋克

https://plnkr.co/edit/EVPDSFAUyr55jDDlVOVV?p=preview

  app.filter("unsafe",function($sce){

        return function(val){
          return $sce.trustAsHtml(val);
        }
      })

您應該使用過濾器和ng-bind-html來解析html內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM