I have checkboxes and a share button. On click of share button the selected checkbox link will be shared via mail. The mail body will have diet name and on click of the name the user will be redirected to its URL.
As of now I am able to store the seteled diet URL is an array and mail is also pooping up but I cannot see the hyperlink, the mail body looks like this.
Click below
<a href=www.sugar.com>sugar</a>
I want it to be like this:
Click below
bread
butter
sugar
where bread, butter, sugar will be hyperlinks. I am able to form a correct URL but it is not aapearing as a hyperlink in the mail body.Please guide me how to achieve this. Where did I go wrong?? Is there an angular way to achieve this?
Below ia my working code:
ts file
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 6';
diets = [{
'name': 'bread',
'url': 'www.bread.com'
},
{
'name': 'butter',
'url': 'www.butter.com'
},
{
'name': 'sugar',
'url': 'www.sugar.com'
}];
downloadURL = [];
mailText:string = "";
mailMe(){
var elements = (<HTMLInputElement[]><any>document.getElementsByClassName("selFile"));
for (let i = 0; i < elements.length; i++) {
if (elements[i].type == "checkbox") {
if (elements[i].checked) {
this.downloadURL.push('<a href='
+elements[i].value+'>'+elements[i].name+'</a>');
}
}
}
console.log("this.downloadURL: ",this.downloadURL);
this.mailText = "mailto:abc@abc.com+?subject=files&body=Click below"+this.downloadURL.join(" ,"); // add the links to body
window.location.href = this.mailText;
}
}
HTML
<div *ngFor="let diet of diets">
<span>
<input type='checkbox' class="selFile" value="{{diet.url}}" name='{{diet.name}}' />
</span>
<span>{{diet.name}}</span>
share