我正在尝试在我的 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/