html中href的替代形式是什么?

问题描述 投票:0回答:2

我想在component.ts文件中定义const url,以便我可以对其进行测试并在html文件中访问此url。有一些使用ngHref的解决方案,但在我的情况下不起作用。如何在component.ts文件中定义comst url,在html文件中定义ccess。这是我的html代码

    <a [ng-href]="{{href}}" {{href}} target="_blank">Show</a>

这是我的component.ts文件

export class Table implements OnInit {
  public href = `www.yahoo.com
  }
html angular href
2个回答
0
投票

您可以使用此:

public myLink = "https://yahoo.com";
…
<a [href]="myLink" target="_blank">Show</a>

-1
投票

您可以简单地绑定值:

export class Table implements OnInit {
  public variableName = 'https://www.yahoo.com';
}
<a [href]="variableName">Some Clickable Link</a>
© www.soinside.com 2019 - 2024. All rights reserved.