gpt4 book ai didi

javascript - 如何处理确认框的取消事件?

转载 作者:太空狗 更新时间:2023-10-29 19:33:41 24 4
gpt4 key购买 nike

如何处理确认框的取消事件?我的目转到上一页,但在这两种情况下,它都会转到上一页。this.router.navigate(['user-details]) 根本不工作,而 window.history.pushState({}, "user-details", "/user-details"); 是只是更改 url,而不是页面。

export class UserDetailsComponent implements OnInit, OnDestroy {
r: boolean;
confirmtxt;
canceltxt;
paymentList = [];
constructor(
private router: Router,
private dataService: DataService,
private location: Location
) {
this.getPaymentSummaryData();
}

ngOnInit() {
this.location.subscribe(x => {
console.log(this.location);
console.log(x);
if (x.type === "popstate") {
console.log("data is " + this.paymentList.length);
const str = String(this.paymentList.length);
console.log(str);
this.r = confirm(
"Are you sure?" +
" " +
str +
" " +
"applications are in the queue, awaiting decision."
);
console.log(this.r);
if (this.r === true) {
// txt = "You pressed OK!";
this.confirmtxt = "ok";
} else {
this.r = false;
// history.forward();
}
}
});
console.log(this.r);
}
ngOnDestroy() {
console.log('in destroy' + this.r);
if (this.r === false) {
this.router.navigate(['user-details']);
window.history.pushState({}, "user-details", "/user-details");
this.router.navigate(["user-details"]);
window.location.reload();
}
// this.location.unsubscribe();
}
}

最佳答案

我不知道为什么 this.router.navigate(['url']) 不工作。所以我将其更改为 this.router.navigateByUrl('/url') 方法。此外, bool 值在开始时将为 undefined,因此也需要检查它。ngOnDestroy() 中的这两个更改对我都有效。

ngOnDestroy() {
console.log('in destroy' + this.r);
if (this.r === false) {
this.router.navigateByUrl('/user-details');

} else if ( !this.r ) {
this.router.navigateByUrl("/user-details");
}
// this.location.unsubscribe();
}

关于javascript - 如何处理确认框的取消事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48094612/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com