Welcome to my first Stack Overflow question! I usually find the answers I need on my own, but this time I could use some guidance as I delve into Angular.
I have a directive that pulls the name and URL from a JSON object and generates HTML with the name and a hyperlink. The issue is that the JSON response for the URL can be entered in various formats by users using a CMS, without any backend validation. This means the URL can appear as www.blah.xxx or , among other possibilities. Is there an Angular solution (without relying on a plugin) to check if the URL includes "http://" and automatically add it if not? Or perhaps there's a reliable plugin that can handle this task effortlessly?
angular.module('pwrApp')
.directive("getPrimaryCareProviderName", [function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
scope.$watch('primaryCareProvider', function() {
var output = "";
if(scope.primaryCareProvider.site == "" || scope.primaryCareProvider.site ===null){
output = scope.primaryCareProvider.name;
}else{
output = '<a href="'+scope.primaryCareProvider.url+'" target="_BLANK">'+scope.primaryCareProvider.name+"</a>";
}
elem.html(output);
});
}
}
}]);