11

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

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'm running into an issue where I'm getting an error:

Cannot assign to 'location' because it is a constant or a read-only property. webpack: Failed to compile.

The examples I've seen so far all describe doing it thie way, with "window.location", so how can I resolve this issue?

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Muirik
  • 6,049
  • 7
  • 58
  • 116
  • Possible duplicate of https://stackoverflow.com/questions/13106950/set-window-location-with-typescript – amiramw Jun 14 '17 at 19:19

1 Answers1

19

You're missing the href

window.location.href = ....

You can also do this with the Angular Router by giving it a static url:

this.router.navigateByUrl('url')
joh04667
  • 7,159
  • 27
  • 34