我从我的数据库中获取有关组织的信息。以下是组织的界面结构:
interface IOrganization {
id: number;
name: string;
url: string;
createdAt: Date;
}
Run Code Online (Sandbox Code Playgroud)
现在我想像这样显示它们:
<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>
Run Code Online (Sandbox Code Playgroud)
不幸的是,链接不起作用。每当我将鼠标悬停在链接上时,我都会获取包括基本 href 的信息。
假设我的组织链接是www.google.com.,每当有人点击时,用户应该重定向到组织。但每当我点击链接时,我都会收到类似的信息。
http:// localhost:4200/organizations/www.google.com
Run Code Online (Sandbox Code Playgroud)
如何从链接中删除基本 href,以便用户在单击链接时可以轻松访问 google.com?
啊我得到了答案:
<a mat-list-item [attr.href]="'//'+ org.url "> {{ org.name }} </a>
Run Code Online (Sandbox Code Playgroud)
这行代码解决了这个问题。 欲了解更多详情,请点击此链接
| 归档时间: |
|
| 查看次数: |
2515 次 |
| 最近记录: |