【发布时间】:2020-04-15 16:56:57
【问题描述】:
我尝试使用 window.open() 函数,但它会打开一个带有 URL localhost:4200/www.google.com 的新窗口,大约 3 秒后它会刷新回 localhost,在控制台中显示此错误:: “未捕获(承诺):错误:无法匹配任何路由。URL 段:'www.google.com' 错误:无法匹配任何路由。URL 段:'www.google.com'” (存储在数据库中的链接是 www.google.com 来测试它。) 这是代码。我需要加载没有 localhost 作为其域的 URL。
HTML
<ng-container matColumnDef="documents">
<th mat-header-cell *matHeaderCellDef> Documents </th>
<td mat-cell *matCellDef="let user">
<button class="btn btn-primary medium" style="margin-left: 5px;"
(click)="viewdocuments(user.link)">View</button>
</td>
</ng-container>
TS
`viewdocuments(link: string): void {
window.open(link);
}
【问题讨论】:
-
您必须在从 db 获得的链接之前添加
http://。例如它应该像window.open(http://www.google.com) -
@RanjithS 成功了。干杯伙伴!
标签: mysql angular typescript url-routing