I want to check if user he is coming from page 1 or page 2 using current url route , then pass parameters depending on page url . I used if statement and ngif to checking the current url route . But problem is the if statement doesn't work properly .
code :
page1:boolean= false
page2:boolean= false
constructor(private router:Router) {
if (this.router.url === '/tabs/tab1') {
this.page1= true
this.page2= false
this.getData()
} else if (this.router.url === '/tabs/tab2'){
this.page1= false
this.page2= true
this.getData()
}
}
html
<ng-container *ngIf="page1; else elseTemplate">
// check if page 1 route /tabs/tab1' display data page1 and hide data
page 2
// for page 1 different data
</ng-container>
<ng-template #elseTemplate>
</ng-template>
<ng-container *ngIf="page2; else elseTemplate">
// check if page2 route /tabs/tab2' display data page 2 and hide
data page 1
// Also of paga 2 different data
</ng-container>
<ng-template #elseTemplate>
</ng-template>
Aucun commentaire:
Enregistrer un commentaire