Javascript 获取错误:';无法分配给';地点';因为它是常量或只读属性';在Angular应用程序中使用mailto功能
我正在尝试在Angular 2应用程序中设置一个功能,该功能将使用用户的默认电子邮件客户端发送电子邮件,其中包含一些预先填充的信息:Javascript 获取错误:';无法分配给';地点';因为它是常量或只读属性';在Angular应用程序中使用mailto功能,javascript,angular,typescript,mailto,Javascript,Angular,Typescript,Mailto,我正在尝试在Angular 2应用程序中设置一个功能,该功能将使用用户的默认电子邮件客户端发送电子邮件,其中包含一些预先填充的信息: sendEmail() { this.title = document.title; this.title = this.title.replace("&", "-"); window.location = "mailto:?body=" + this.title + " - " + window.location + "&
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.";
}
但我遇到了一个错误:
无法分配给“位置”,因为它是常量或只读
财产。网页包:未能编译
到目前为止,我看到的示例都描述了这样做的方式,即“window.location”,那么我如何解决这个问题呢?您缺少
href
window.location.href = ....
您也可以通过为Angular路由器提供一个静态url来实现这一点:
this.router.navigateByUrl('url')
可能重复的