html - Angular使组件的一部分不可点击
问题描述
所以我有这个组件,它是一个按钮,当点击它时,它会导航到某个路线。但是,我想在其中放置一个按钮,这不会使其导航并执行其他操作。
我该怎么做呢?它是关注/取消关注按钮。
<button type="button" class="btn" (click)='navigate()' *ngIf="searchResult.username"><mat-card>
<mat-card-header>
<mat-card-title>{{searchResult|null:['firstname']}} {{searchResult|null:['lastname']}}</mat-card-title>
</mat-card-header>
<mat-card-content class="container">
<div>{{searchResult|null: ['username']}}</div>
<div>
<!-- option to follow -->
<div *ngIf="!result.followers.includes(this.selfUsername)" class="follow">
<button mat-raised-button (click)="onFollow()">
Follow
</button>
</div>
<!-- already following -->
<div *ngIf="result.followers.includes(this.selfUsername)" class="follow">
<button mat-raised-button (click)="onUnfollow()">
Unfollow
</button>
</div>
</div>
<div>
<!-- dunno why these dont work -->
<!-- <p *ngFor="let item of searchResult|null:['history']">{{item}}</p> -->
</div>
<div>
<!-- <p *ngFor="let item of searchResult|null:['whishlist']">{{item}}</p> -->
</div>
</mat-card-content>
</mat-card>
</button>
解决方案
仅在进行交互时使用按钮标签,例如调用执行某些操作的函数。
在你的情况下,如果你想放置任何按钮,你想在某个地方“超链接”(在这种情况下它是一张垫卡)和里面......比方说。
对于导航,您应该始终使用锚标记,例如<a ... href="" 或 routerLink="">...content </a>
所以,只需将根 <button ...> 更改为 <a ...>.....
应该就是这样。
推荐阅读
- identityserver3 - IdentityServer3 适用于 Chrome,但为 Internet Explorer (Edge) 获取 invalid_client
- python - python - 试图将一个 csv 文件变成一个更干净的 csv!python 和 Stack 的新手
- python - 如何在 CountVectorizer 中对句子应用权重(计算每个句子标记数次)
- javascript - 在 Cypress 内的转译 Vue 组件中加载 CSS 样式表
- javascript - 调整文本大小以适应可扩展内容可编辑?
- java - 从一个jsp中获取一个字符串来创建另一个jsp
- python - 使用多循环和 ET 在 Python 中解析 XML
- python - 为什么我们把整数放在第三位?
- java - Java/JTable - 改变 JTable 滚动条的大小
- encryption - 在经典 ASP 中验证 Stripe Webhook 签名