How can I convert the following code into an asynchronous function? It is currently returning referralUrl as undefined:
controller
async createReferralUrls() {
this.referralUrl = await this.referralService.generateReferralUrl(this.userData.referralId);
this.campaignMessage = 'Sign up here: ' + this.referralUrl + '.';
this.facebookShareUrl = 'http://www.facebook.com/sharer/sharer.php?u=' + this.referralUrl;
this.whatsappShareUrl = 'https://wa.me/?text=' + this.campaignMessage;
this.twitterShareUrl = 'https://twitter.com/intent/tweet?text=' + this.campaignMessage;
this.emailShareUrl = 'mailto:?subject=Welcome to our site!&body=' + this.campaignMessage;
}
html
<input type="text" class="form-control" placeholder="" value="{{ referralUrl }}" readonly>
referralService
generateReferralUrl(referralId) {
if (location.host === 'localhost:4200') {
return 'localhost:4200/invite/' + referralId;
} else if (location.host === 'myapp.herokuapp.com') {
return 'myapp.herokuapp.com/invite/' + referralId;
} else if (location.host === 'myapp.com') {
return 'myapp.com/invite/' + referralId;
}
}