How can I conditionally use either [href] or [routerLink] on an anchor?

后端 未结 5 1738
暖寄归人
暖寄归人 2021-01-01 11:56

I need for the same anchor link to be pointed conditionally locally or to external resource. I tried



        
5条回答
  •  一整个雨季
    2021-01-01 12:23

    For a conditional href, prepending on attr. before the href worked for me using null as a value, like this:

    [attr.href]="!item.subMenu ? item.url : null"
    

提交回复
热议问题