Skip to main content
added 388 characters in body
Source Link
Sebastian
  • 17.5k
  • 5
  • 51
  • 57

What aboutUpdate

Or use a directive:

module.directive('myTarget', function () {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
          var href = element.href;
          if(true) {  // replace with your condition
            element.attr("target", "_blank");
          }
        }
    };
});

Usage:

<a href="http://www.google.com" my-target>Link</a>

When you don't need to use this with Angular routing you can simply use this:

<a href="http://www.google.com" target="{{condition ? '_blank' : '_self'}}">Link</a>

What about this:

<a href="http://www.google.com" target="{{condition ? '_blank' : '_self'}}">Link</a>

Update

Or use a directive:

module.directive('myTarget', function () {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
          var href = element.href;
          if(true) {  // replace with your condition
            element.attr("target", "_blank");
          }
        }
    };
});

Usage:

<a href="http://www.google.com" my-target>Link</a>

When you don't need to use this with Angular routing you can simply use this:

<a href="http://www.google.com" target="{{condition ? '_blank' : '_self'}}">Link</a>
Source Link
Sebastian
  • 17.5k
  • 5
  • 51
  • 57

What about this:

<a href="http://www.google.com" target="{{condition ? '_blank' : '_self'}}">Link</a>