你如何制作<a> link disabled using condition?

时间:2018-04-27 21:11:54

标签: html angular

I use angular 4 how can I disable the <a> element with a condition doing something like this [disabled]="!f.form.valid"

<a class="btn btn-primary btn-lg disabled" 
        href="https://mailtrap.io/inboxes/354346/messages" 
        target="_blank" (click)=f.form.reset() > Verify your Email Now</a>

If you suggest to just use the link button so I want to konw how to add target="_blank"

1 个答案:

答案 0 :(得分:0)

将样式归功于this excellent post in css-tricks

.isDisabled {
  color: currentColor;
  cursor: not-allowed;
  pointer-events: none
  opacity: 0.5;
  text-decoration: none;
}

<a [ngClass]="{'isDisabled':condition}"
   class="btn btn-primary btn-lg disabled" 
   href="https://mailtrap.io/inboxes/354346/messages" 
   target="_blank" (click)=f.form.reset() > Verify your Email Now</a>