我想在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
}
您可以使用此:
public myLink = "https://yahoo.com";
…
<a [href]="myLink" target="_blank">Show</a>
您可以简单地绑定值:
export class Table implements OnInit {
public variableName = 'https://www.yahoo.com';
}
<a [href]="variableName">Some Clickable Link</a>