如何删除 localhost:4200 url 附加在 <a> 标签中的 [href] 属性中

问题描述

以下是 HTML:

 <a [href]= "message.messagelinkHere ? sanitize(message.messagelinkHere) : message.messagelink"

在 ts 文件

 import { DomSanitizer } from '@angular/platform-browser';

constructor(public sanitizer:DomSanitizer) { }
 sanitize(url:string) {
  let sanitizedUrl;
  sanitizedUrl = this.sanitizer.bypassSecurityTrustResourceUrl(url)
  console.log(sanitizedUrl) //SafeValue must use [property]=binding:/(https://urldefense.proofpoint.com/v2/url?u=https-3A__nam11.safelinks)
  return sanitizedUrl;
 }

尝试访问附加了 http://localhost:4200/https://urldefense.proofpoint.com/v2/url?u=https-3A__nam11.safelinks 的 URL 和链接正在打开本地应用程序,而不是外部网站。

能否请您告诉我如何删除附加在 href 中的本地主机

解决方法

这是我没有使用 Dom sanitizer 而是直接使用字符串插值保留 URL 来标记的解决方案。

https://stackblitz.com/edit/angular-ivy-xe5gzz?file=src%2Fapp%2Fapp.component.html