/ 设置 10 秒超时 // 每日统计清 0 runtime_set('todaycomments', 0); runtime_set('todayarticles', 0); runtime_set('todayusers', 0); if ($forumlist) { $fidarr = array(); foreach ($forumlist as $fid => $forum) { $fidarr[] = $forum['fid']; } forum_update($fidarr, array('todayposts' => 0, 'todaythreads' => 0)); } // 清理临时附件 attach_gc(); // 当天24点 $today = strtotime(date('Ymd')) + 86400; runtime_set('cron_2_last_date', $today, TRUE); // 往前推8个小时,尽量保证在前一天 升级过来和采集的数据会很卡 // table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } } ?>javascript - How to use replace & with & in angularjs - Stack Overflow|Concepts Of Algorithm

javascript - How to use replace & with & in angularjs - Stack Overflow

admin2025-04-20  1

Problem: I am having a hard time to replace"&amp ;" to &. Is their a way to use javascript to replace the ampersand to &.

<div class="col-md-4 no-margin padding" id="change">
 <strong>Specialty: </strong>{{e.Specialty}}
</div>

I would like to replace the "&amp ;" when it grabs the data from the database to "&".

So currently, it will display "Nursing &amp ; Doctor" rather then "Nursing & Doctor"

How can I achieve this using replace. I have tried ng-show, Santize, and ng-bind-html but have not worked out for me.

Problem: I am having a hard time to replace"&amp ;" to &. Is their a way to use javascript to replace the ampersand to &.

<div class="col-md-4 no-margin padding" id="change">
 <strong>Specialty: </strong>{{e.Specialty}}
</div>

I would like to replace the "&amp ;" when it grabs the data from the database to "&".

So currently, it will display "Nursing &amp ; Doctor" rather then "Nursing & Doctor"

How can I achieve this using replace. I have tried ng-show, Santize, and ng-bind-html but have not worked out for me.

Share Improve this question asked Sep 19, 2017 at 17:13 RobertRobert 1671 gold badge2 silver badges14 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2

This is not necessarily the best way but for those of you that need to do this you can use this:

var parser = new DOMParser;
var dom = parser.parseFromString(YOURSTRING,'text/html');
var decodedString = dom.body.textContent;

You have to use $sce service and trustAsHtml so that Angular will not do the encoding and display the output without output encoding. Details are here https://docs.angularjs/api/ngSanitize

Steps are below-

  1. Include ngSanitize module - angular.module('app', ['ngSanitize']);
  2. Inject $sce service in your controller
  3. Truest output using - vm.Specialty= $sce.trustAsHtml(Specialty);
  4. Display to the user without output encoding - Specialty: bind-html-pile=e.Specialty

This can be done using

<span ng-bind-html="e.Specialty"></span>

and include ['ngSanitize'] in your module

plunkr example: https://plnkr.co/edit/d6Anjr7vL6un9d0yL5ZW?p=preview

I would use a filter...

JavaScript:

myApp.filter('andFilter', function() {
  return function(item) {
    return item.replace(/&amp ;/g, '&');
  }
});

HTML:

<div class="col-md-4 no-margin padding" id="change">
 <strong>Specialty: </strong>{{e.Specialty | andFilter}}
</div>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745158417a287997.html

最新回复(0)