我有一个场景,其中我有多个页面,在这些页面上,所有形式的应用程序级别都有后退箭头图标。我试图将app.component.html中的后退箭头设置为所有表单中的通用箭头。但是某些表格没有后退箭头。我只需要为这些表格隐藏后退箭头。为了隐藏某些表格的后退箭头(例如otp.component.ts),我尝试匹配url字符串名称,并在用户到达该特定表格时隐藏后退箭头。这是我在app.component里面做的。这不起作用,因为应用程序组件仅在应用程序加载时加载一次。是否有任何方法可以实现此方案。
可能是我需要匹配otp.component.ts中的字符串逻辑,并将布尔值传递给app.component.html。但我不确定如何实现。
对此提供了任何帮助,我们深表感谢。谢谢。
app.component.html :
<button class="header_back" *ngIf="showBackIcon" (click)="goBack()"></button>
<button class="header_close" *ngIf="showCloseIcon" (click)="close()"></button>
app.component.ts:
constructor() {
const urlPath = window.location.href;
if (urlPath.indexOf("/otp") > -1) {
this.showCloseIcon=true;
this.showBackIcon=false;
} else {
this.showCloseIcon=false;
this.showBackIcon=true;
}
}
创建一个注入的服务,该服务执行路径检查逻辑并分配给服务内的属性。