动态地,我从我的服务器以 json 格式获取 HTML 内容。
{ "title":"Home", "name":"ss_home", "content":"<div class=\"ExternalClass3dfsfsf204E51\"><table id=\"layoutsTable\" style=\"width:100%;\"><tbody><tr style=\"vertical-align:top;\"><td style=\"width:100%;\"><div class=\"ms-rte-layoutszone-outer\" style=\"width:100%;\"><div class=\"ms-rte-layoutszone-inner\"><div class=\"ms-rtestate-read ms-rte-embedcode ms-rtestate-notify ms-rte-embedil s4-wpActive\" unselectable=\"on\"><table border=\"1\" width=\"850\" unselectable=\"on\"><tbody unselectable=\"on\"><tr unselectable=\"on\"><td unselectable=\"on\"> \r\n <strong unselectable=\"on\">Quality Policy:</strong><br unselectable=\"on\"><strong unselectable=\"on\" style=\"line-height:20px;\"><em unselectable=\"on\">“Some content”.</em> </strong></td></tr><tr unselectable=\"on\"><td unselectable=\"on\">\r\n <strong unselectable=\"on\">Deriving Project Quality Objectives-Approach</strong><span unselectable=\"on\" style=\"line-height:19px;\"> </span>\r\n <img width=\"850\" height=\"414\" src=\"/org/Data/Home-page.png\" title=\"Home page\" class=\"alignnone size-large wp-image-34364857\" unselectable=\"on\" data-themekey=\"#\" alt=\"\" />   </td></tr></tbody></table> \r\n <span unselectable=\"on\" style=\"line-height:30px;\">\r\n <br unselectable=\"on\">\r\n <strong unselectable=\"on\">Organization Chart</strong></span><img width=\"650\" height=\"350\" src=\"/org/Data/Org_chart.jpg\" title=\"Org chart\" class=\"alignnone size-large wp-image-34138132\" unselectable=\"on\" data-themekey=\"#\" alt=\"\" /></div><p><a class=\"link_nav\" data-action=\"project_initiation\" href=\"#\" title=\"Project Initiation\" unselectable=\"on\">Project Initiation</a> \r\n <br> </p></div></div></td></tr></tbody></table><span id=\"layoutsData\" style=\"display:none;\">false,false,1</span></div>" }
组件.ts
<div class="content" [innerHTML]="pq.content_QMS | safeHtml"></div>
sat.html.pipe.ts
transform(value) {
return this.sanitized.bypassSecurityTrustHtml(value); }
我没有其他选择可以更改此 html 内容。但是,对于我的应用程序,我必须实现两件事,
- 更改图像路径
- 添加点击事件
最终输出应该是:
<img src="/org/Data/Org_chart.jpg" /> to <img src="http://example.com/org/Data/Org_chart.jpg"
和
<a class="link_nav" data-action="project_initiation" href="#" title="Project Initiation"> to <a class="link_nav" (click)="project_initiation" href="#" title="Project Initiation">
我们如何使用任何管道正则表达式或其他逻辑来实现它?给我一些关于它的功能建议。