Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取错误:';无法分配给';地点';因为它是常量或只读属性';在Angular应用程序中使用mailto功能_Javascript_Angular_Typescript_Mailto - Fatal编程技术网

Javascript 获取错误:';无法分配给';地点';因为它是常量或只读属性';在Angular应用程序中使用mailto功能

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 + "&

我正在尝试在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.";
}
但我遇到了一个错误:

无法分配给“位置”,因为它是常量或只读 财产。网页包:未能编译


到目前为止,我看到的示例都描述了这样做的方式,即“window.location”,那么我如何解决这个问题呢?

您缺少
href

window.location.href = ....
您也可以通过为Angular
路由器提供一个静态url来实现这一点:

this.router.navigateByUrl('url')
可能重复的