【问题标题】:How to display a specific page based on the URL taken from the DB in Angular?如何根据从 Angular 中的数据库获取的 URL 显示特定页面?
【发布时间】: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


【解决方案1】:

尝试使用带有第二个参数“_blank”的 window.open。 例如:

window.open(file_url, '_blank');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 2011-08-11
    • 2020-05-20
    相关资源
    最近更新 更多