gpt4 book ai didi

javascript - 获取错误 : 'Cannot assign to ' location' because it is a constant or a read-only property' with mailto function in Angular app

转载 作者:数据小太阳 更新时间:2023-10-29 04:05:01 25 4
gpt4 key购买 nike

我正在尝试在我的 Angular 2 应用程序中设置一个功能,该功能将使用用户的默认电子邮件客户端发送一封包含一些预填充信息的电子邮件:

sendEmail() {
this.title = document.title;
this.title = this.title.replace("&", "-");
window.location = "mailto:?body=" + this.title + " - " + window.location + "&subject=I thought this link might interest you.";
}

但是我遇到了一个错误:

Cannot assign to 'location' because it is a constant or a read-only property. webpack: Failed to compile.

到目前为止我看到的例子都描述了如何使用“window.location”,那么我该如何解决这个问题呢?

最佳答案

您缺少 href

window.location.href = ....

您也可以通过给 Angular Router 一个静态 url 来做到这一点:

this.router.navigateByUrl('url')

关于javascript - 获取错误 : 'Cannot assign to ' location' because it is a constant or a read-only property' with mailto function in Angular app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44552984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com