gpt4 book ai didi

新选项卡上的 Angular 6 routerLink

转载 作者:行者123 更新时间:2023-12-03 12:40:43 24 4
gpt4 key购买 nike

我正在尝试在新选项卡上而不是在当前页面上打开一个路由器链接,但是像 target _blank 这样的常规 html 属性不起作用。

<span routerLink="/custompage/{{city.id}}"  class="badge badge-primary badge-pill">open</span>

最佳答案

这是在组件内执行的另一种方法。

openCityInNewWindow(city) {
// Converts the route into a string that can be used
// with the window.open() function
const url = this.router.serializeUrl(
this.router.createUrlTree([`/custompage/${city.id}`])
);

window.open(url, '_blank');
}

Html 看起来像
<ul *ngFor="let city of cities">
<li (click)="openCityInNewWindow(city.id)">{{city.name}}</li>
</ul>

关于新选项卡上的 Angular 6 routerLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54483451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com