'Redirect and at the end of navigation call another method. Angular 5
I have a login screen, a landing screen and a Modal Popup Screen.
One of the scenarios is User successfully Logs In --> Show Landing page --> Show Modal Popup screen.
Login.ts : has the code to Redirect and call another method of a different component.
@ViewChild(ModalPopup)
public modalPoupup: ModalPopup| undefined;
getBillingPage(){
let user = this.userService.getUser();
this.redirect(this.landingPage.toString());
this.modalPoupup.openMyModal();
}
ModalPopup.ts: has the methods to show/hide the Modal
public openMyModal() {
this.myModal.show();
}
The above code successfully redirects but doesn't open the Modal popup.
If I remove the redirect() in the Login.ts and just have openMyModal(), the modal is shown but when the Modal is closed it still shows the Login page instead of Landing page.
Is it possible to achieve this?
Solution 1:[1]
you can use the code router.navigate(['Page']) to redirect the page after the login is complete, you have to import the Router library.
example:
login(){
this.userServ.postlogin(this.users)
.subscribe( (res:any) => {
localStorage.setItem('token',res.token );
console.log(res)
this.router.navigate(['private'])
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Fernando Escoboza |
