In my Typescript-driven Angular 2 application, I am creating an email with some pre-filled information that will open the user's default email client. Currently, I have it working by constructing the mailto string directly in the component like this:
greetingEmail = `<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee9b9d8b9cae8b968f839e828bc08d8183">[email protected]</a>?subject=Family%20Greeting%20Email&body=message%20goes%20here`;
I am using this link within an anchor tag in the view as follows:
<a [href]="'mailto:' + greetingEmail" tabindex="-1">Generate Greeting Email</a>
However, when I attempted to use ES6/ECMA2015 template literals for a more dynamic approach, the email is still generated correctly but the fields (emailAddress, subject, body) appear as 'undefined'. Here is what I tried:
emailAddress: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e491978196a4819c8589948881ca878b89">[email protected]</a>';
subject: 'Family Greeting Email';
body: 'This is where the body of the email goes...';
greetingEmail = `${this.emailAddress}?subject=${this.subject}&body=${this.body}`;
Do you know why the template literal method is not working in this scenario or why the fields are undefined during runtime? Is there something else that could be causing this issue?