Getting error: "Unable to assign" location "because it is a constant or a read-only property" with the mailto function in the Angular application

I am trying to configure a function in my Angular 2 application that will send an email using the user's default email client with some pre-populated information:

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."; } 

But I ran into a problem when I get an error:

It is not possible to assign a "location" because it is persistent or a read-only property. webpack: Failed to compile.

The examples I've seen so far describe this with "window.location", so how can I solve this problem?

+7
source share
1 answer

You miss href

 window.location.href = .... 

You can also do this using Angular Router by giving it a static URL:

 this.router.navigateByUrl('url') 
+10
source

Source: https://habr.com/ru/post/1268851/


All Articles