微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决如何删除 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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。