angular - 具有不同 routerLinks 的 Angular 通知组件未根据输入重定向
问题描述
我需要一些指导。我使用一个小组件来显示通知。在这个组件中,我有一个 routerLink、按钮文本和两个按钮的显示按钮 @Input。在另一个组件中,我为这两个按钮分配了值,并希望根据我的路由器值有不同的路由来重定向用户。
我遇到了一个问题,即secondaryRouterLink 并不总是触发,或者它导航到routerLink 而不是secondaryRouterLink。有时它工作得很好。
下面是我的通知组件:
export class NotificationComponent implements OnInit {
@Input() notificationHeader = null;
@Input() notificationMessage = null;
@Input() buttonText = null;
@Input() routerLink = null;
@Input() showButton = true;
@Input() secondaryButtonText = null;
@Input() showSecondaryButton = false;
@Input() secondaryRouterLink = null;
@Input() showNotification: boolean = false;
showNotificationMessage = new BehaviorSubject<boolean>(false);
constructor(private router: Router) { }
ngOnInit(): void {
this.routerLink = this.router.url;
}
emmitEvent() {
this.close();
this.callParentmethod.emit();
this.router.navigate(['/search']);
}
close() {
// Default stay on current page when closing error pop-up
this.routerLink = this.router.url;
this.showNotificationMessage.next(false);
}
}
这是我的通知视图:
<div class="overlay" *ngIf="showNotification">
<div class="box">
<span class="fs-30 notification-header">{{ notificationHeader }}</span>
<hr />
<p class="notification-message">{{ notificationMessage }}</p>
<div class="">
<button
*ngIf="showButton"
type="button"
class="af-button mt-2 mb-2 float-right mr-3"
[routerLink]="[routerLink]"
(click)="close()"
>
{{ buttonText }}
</button>
<button
*ngIf="showSecondaryButton"
type="button"
class="af-button mt-2 mb-2 float-right mr-3"
[routerLink]="[secondaryRouterLink]"
(click)="close()"
>
{{ secondaryButtonText }}
</button>
</div>
</div>
</div>
这是一个典型的用例,我将为通知组件分配值:
this.showSecondaryButton = true;
this.secondaryRouterLink = '/claims-tracking';
this.secondaryButtonText = 'Track Claim';
this.routerLink = '/search';
this.buttonText = 'Close';
this.showNotification = true;
我将不胜感激任何建议来完成这项工作!
解决方案
推荐阅读
- virtual-machine - 将.ova文件导入VirtualBox后可以删除吗?
- javascript - 单击图像后如何使CSS动画发生
- bash - 使用 awk 将带空格的第一列视为一列
- mysql - 用于 Node.Js 的 Mysql2 是否需要在执行 queires 之前在 mysql.CreateConnection 上运行 connect()
- angular - 角度路由添加随机滚动条
- java - CompilingClassLoader 很有趣,在这种情况下如何从不同的类加载器加载子类?
- python - 如何手动解压 cifar10/100 数据库?简单的解决方案
- java - 线程“主”java.lang.NoClassDefFoundError 中的异常:com/google/common/collect/ImmutableMap
- android - 没有这样的属性:variantConfiguration 类:
- ansible - JMESPath 或 Ansible 扁平化字典