angular - 使用 TS 的 Angular 禁用 href
问题描述
我在使用 Angular 和 Typescript 禁用 href 时遇到问题,我不确定我是否走在正确的道路上。
有没有更好的方法来做这样的事情?用红色圆圈寻找类似的东西
ts
ReadOnlyStyleGuideNotes: boolean;
ngOnInit() {
this.ReadOnlyStyleGuideNotes = true;
}
html
<a href="#"
*ngIf="note.Edited || note.Removed"
(click)="restoreDefault(note)"
style="font-size: 12px"
data-disabled="readOnlyStyleGuideNotes">
restore defaults
</a>
CSS类
a[data-disabled=true] {
color: currentColor;
cursor: not-allowed;
opacity: 0.5;
text-decoration: none;
}
解决方案
使用指针事件 None 并用 span 包装 a 元素,以便您可以应用光标
<span [ngStyle]="{'cursor':readOnlyStyleGuideNotes ? 'not-allowed' :''}"><a
[ngClass]="{'disable':readOnlyStyleGuideNotes}" href="#"
(click)="restoreDefault(note)"
style="font-size: 12px">
restore defaults</a></span>
css
.disable{
color: currentColor;
opacity: 0.5;
text-decoration: none;
pointer-events: none;
}
推荐阅读
- javascript - 如何使我的表格在移动视图中垂直对齐?
- c# - 在unity3d中检测Windows夜灯模式是否
- halide - 如何在超过 1 个通道的缓冲区上使用卤化物 FFT?
- java - Spring Boot - gradlew 测试失败 || 无法加载 ApplicationContext
- sas - 如何在SAS中转置非唯一变量?
- powershell - 打开一个文件,截取文件并关闭它,使用发送到快捷方式
- linux - 在具有相似子文件夹/子树的多个文件夹上使用通配符安全复制 scp 或 rsync
- powershell - 获取事件日志和计数警告
- javascript - 如何在 JavaScript 中根据日期对 API 数据进行排序?
- python - PyCharm & Visual Studio Code:导入包