Getting error: 'Cannot assign to 'location' because it is a constant or a read-only property' with mailto function in Angular app
Getting error: 'Cannot assign to 'location' because it is a constant or a read-only property' with mailto function in Angular app
我正在尝试在我的 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')
我正在尝试在我的 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')