• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

815
Views
send whatsapp message from angular 2 web app

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}}

`

about 3 years ago · Santiago Trujillo
2 answers
Answer question

0

There are two possible techniques to solve your problem:

  1. Property binding

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>
  1. Interpolation

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.

about 3 years ago · Santiago Trujillo Report

0

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<

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error