angular - 如何从角度的外部链接中删除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?
解决方案
啊,我得到了答案:
<a mat-list-item [attr.href]="'//'+ org.url "> {{ org.name }} </a>
这行代码解决了这个问题。 更多详情请点击此链接
推荐阅读
- javascript - 下面的代码适用于函数声明,但不适用于函数表达式
- c# - C# 异步后续调用返回现有任务
- python-3.x - python pandas中列表中几列的groupby行
- excel - 使用数组变量中的工作表数据创建图表
- php - 没有内置函数的数组键比较
- gradle - 在本地或 CI 中构建时如何在 Gradle 中的存储库之间切换
- docker - 在 Ubuntu Docker 容器中安装 Informix CSDK
- c++ - 为什么下面班级的大小是8
- linux - 用于 linux Debian 和 Arch 的 Docker 撰写文件
- android - Kotlin 多平台使用动态交付?