首页 > 解决方案 > 如何从角度的外部链接中删除base-href?

问题描述

从我的数据库中,我得到了有关组织的信息。这是组织的接口结构:

interface IOrganization {
  id: number;
  name: string;
  url: string;
  createdAt: Date;
}

现在我想像这样显示它们:

<div *ngIf="isloading; else content">
  <mat-progress-bar mode="indeterminate" color="warn"></mat-progress-bar>
</div>

<ng-template #content>
  <mat-tab-group>
    <mat-tab label="Organizations List" >
      <mat-card 
        class="example-large-box mat-elevation-z4"
        *ngFor="let org of organizations"
      >
        <mat-nav-list>
          <a mat-list-item href="{{ org.url }}"> {{ org.name }} </a>
        </mat-nav-list>
      </mat-card>
    </mat-tab>
  </mat-tab-group>
</ng-template>

不幸的是链接不起作用。每当我在链接上进行鼠标悬停时,我都会获得包括基本 href 在内的信息。

假设我的组织链接是www.google.com.,每当有人点击时,用户应该重定向到组织。但是每当我点击链接时,我都会得到类似的东西。

http:// localhost:4200/organizations/www.google.com

如何摆脱链接中的基本 href,以便用户在点击链接时可以轻松访问 google.com?

标签: angular

解决方案


啊,我得到了答案:

<a mat-list-item [attr.href]="'//'+ org.url "> {{ org.name }} </a>

这行代码解决了这个问题。 更多详情请点击此链接


推荐阅读