Skip to content

Instantly share code, notes, and snippets.

@thewarpaint
Last active December 22, 2015 09:49
Show Gist options
  • Save thewarpaint/6454594 to your computer and use it in GitHub Desktop.
Save thewarpaint/6454594 to your computer and use it in GitHub Desktop.
Angular directive to generate a normal link and another one to be opened in a new window/tab from a URL.
angular.module('LinkWidget')
.directive('linkWidget', function() {
var directive = {
template: '<span><a ng-href="{{ url }}" target="_blank" class="external-link add-tooltip" title="{{ blankTitle }}"><i class="icon-external-link"></i></a> ' +
'<a ng-href="{{ url }}">{{ text }}</a></span>',
replace: true,
restrict: 'EA',
scope: {
url: '@url',
text: '@text',
blankTitle: '@blankTitle'
},
controller: ['$scope', function($scope) {
$scope.blankTitle = $scope.blankTitle || 'Open in a new window or tab';
}]
};
return directive;
});
<!-- Depends on FontAwesome to display the external-link icon. -->
<link-widget url="http://manoderecha.mx" text="A project management web app."></link-widget>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment