如何解决为什么组件内的订阅者没有在 angulat 中更新 ngOninit 之外的值
的更新值ngOnInit 上的 prevIoUsUrl 和 currentUrl 但是当我点击取消时,我得到了更新的值,请帮忙
export class LoginComponent implements OnInit {
prevIoUsUrl;
currentUrl;
constructor(private authService: AuthService,private router: Router,private changeDetector: ChangeDetectorRef) {}
ngOnInit(): void {
this.router.events.pipe(
filter((event) => event instanceof NavigationEnd)
).subscribe((event: NavigationEnd) => {
this.prevIoUsUrl = this.currentUrl;
this.currentUrl = event.url;
//this.routes.push('this.prevIoUsUrl')
});
}
onSubmitLoginForm(loginForm: NgForm): void {
this.authService.doGetFormDetails(loginForm.form.value)
this.onCancelLoginForm(loginForm);
}
// cancel button clicked on component
onCancelLoginForm(loginForm: NgForm): void {
console.log(this.prevIoUsUrl)
loginForm.reset()`enter code here`
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。