Building a web app using angular 2, (or 4). Want to send a message through whatsapp. This works fine whatsapp://send?text=hi!
to open whatsapp from the browser. I want to send the url of the current page. I can use {{url}} to print the url on the web page but I don't know how to set text={{url}} if you know what I mean.
relevant part of the component `
export class ActivityDetailsComponent implements OnInit {
@Input() activity: any;
@Output() close = new EventEmitter();
error:any;
navigated = false;
sub: any;
imageURL: string;
location:Location;
url: any;
constructor(private activitiesService:ActivitiesService,
private route: ActivatedRoute,
private router: Router,
private pics: PicsService,
location:Location
) {
this.location = location;
this.url = this.location.path();
}
`
relevant html `
Send a link to this activity to your
<a href="whatsapp://send?text=http://ec2-52-209-95-130.eu-west-
1.compute.amazonaws.com:4200/activities/58c003d47513092fac820f09">whatsapp</a>
contacts
http://ec2-52-209-95-130.eu-west-1.compute.amazonaws.com:4200{{url}}
`
There are two possible techniques to solve your problem:
We use square brackets to tell angular to resolve the value of the href field. Additionally we use simple string concatenation:
<a [href]="'http://example.org/?test=' + url">whatsapp</a>
This is technique uses the curly brackets and is the one you tried to use:
<a href="{{'http://example.org/?test=' + url}}">whatsapp</a>
In your case you can chose the solution you prefer, the official documentation (same link as above) states the following:
When rendering data values as strings, there is no technical reason to prefer one form to the other. You lean toward readability, which tends to favor interpolation. You suggest establishing coding style rules and choosing the form that both conforms to the rules and feels most natural for the task at hand.
Use the following code to do it
var url = document.URL var red = (url.substr(url.lastIndexOf('=') + 1)); window.location.replace("https://api.whatsapp.com/send?text=" + red);
Or you can use the permanent link below to go directly without any script
https://www.educlick.page/p/whats-app-redirect.html?url>url encode<