Angular 使用 link 转到外部页面
Angular go to outside page using link
使用 link 在项目外打开另一个页面
<div class="info-line">
<mat-icon class="s-20 ml-2">
language
</mat-icon>
<a class="h3" href="https://www.google.kz/">
Web Page
</a>
</div>
但是当点击 link 时,打开了这个页面:http://localhost:4200/google.kz - 本地页面,而不是 "google.kz"
如何制作,打开 google.kz 站外 link,而不是尝试在本地页面中查找?
您可以按如下方式使用target="blank"
。
<a class="h3" href="https://www.google.kz/" target="_blank">
Where to display the linked URL, as the name for a browsing context (a tab, window, or iframe
).
_blank
: usually a new tab, but users can configure browsers to open a new window instead.
它应该按照您描述的方式工作,但另一种方法是使用 document.location api.
示例:
<div class="info-line">
<mat-icon class="s-20 ml-2">
language
</mat-icon>
<a class="h3" (click)="navigate()">
Web Page
</a>
</div>
在您的组件内:
navigate(){
document.location = "https://www.google.kz/"
}
使用 link 在项目外打开另一个页面
<div class="info-line">
<mat-icon class="s-20 ml-2">
language
</mat-icon>
<a class="h3" href="https://www.google.kz/">
Web Page
</a>
</div>
但是当点击 link 时,打开了这个页面:http://localhost:4200/google.kz - 本地页面,而不是 "google.kz"
如何制作,打开 google.kz 站外 link,而不是尝试在本地页面中查找?
您可以按如下方式使用target="blank"
。
<a class="h3" href="https://www.google.kz/" target="_blank">
Where to display the linked URL, as the name for a browsing context (a tab, window, or
iframe
).
_blank
: usually a new tab, but users can configure browsers to open a new window instead.
它应该按照您描述的方式工作,但另一种方法是使用 document.location api.
示例:
<div class="info-line">
<mat-icon class="s-20 ml-2">
language
</mat-icon>
<a class="h3" (click)="navigate()">
Web Page
</a>
</div>
在您的组件内:
navigate(){
document.location = "https://www.google.kz/"
}