I ran into an unsafe URL problem after using $ compileProvider.aHrefSanitizationWhitelist (/ ^ \ s * (whatsapp): /); when i read the angular docs it says:
aHrefSanitizationWhitelist ([regular expression]); Retrieves or overrides the default default regular expression, which is used to remove secure URLs during [href] disinfection. Disinfection is a security measure designed to prevent XSS attacks through html links. Any url that needs to be bound to [href] via data binding is first normalized and converted to an absolute URL. Subsequently, the URL maps to the regular expression aHrefSanitizationWhitelist. If a match is found, the original url is written to dom. Otherwise, the absolute url has the string prefix "unsafe:", and only after that it is written to the DOM. "If a match is found, the original url is written to dom. Otherwise, the absolute url is prefixed with the string" unsafe: ", and only then is it written to the DOM." Thus, for all other URLs except whatsapp, the match will not be found and it will be marked as unsafe
Another way to make a directive
angular.module('shareLink') .directive('whatsApp', function (){ return{ link: function (scope, elem, $attr){ elem.on('click', function (){ var text = $attr.text; var url = $attr.whatsApp; var message = encodeURIComponent(text) + " - " + encodeURIComponent(url); var whatsapp_url = "whatsapp://send?text=" + message; window.location.href = whatsapp_url; }); } } });
<a class="sharelink whatsapp" data-action="share/whatsapp/share" data-text="you can add title or any text here" whats-app="{{url}}"> <i class="fa fa-whatsapp "></i> WHATSAPP </a>
source share