Tengo una página que uso para mostrar 3 html diferentes dependiendo de dónde se llame.
En una página tengo:
openCreateAnagraphics(){ this.router.navigate(["/anagraphics", {customerUpdate: true}]); }Así que voy a navegar a anagraphics.
ahí tengo en mi anagraphics.page.ts:
ngOnInit() { this.handleParams(); } handleParams() { let params = this.route.snapshot.params; console.log("this.route.snapshot", this.route.snapshot) console.log("params", params) this.customerUpdate = params.customerUpdate ? params.customerUpdate : false console.log("this.customerUpdate ", this.customerUpdate) }y en anagraphics.page.html
<div *ngIf="...."> <div> //this is showed if I come from another way </div> </div> <div *ngIf="customerUpdate"> <div> HELLO // there is the problem </div> </div>pero solo veo una página en blanco y mi url es
http://localhost:4200/anagraphics;customerUpdate=true
Me gustaría obtener que si hago clic en el botón que llama openCreateAnagraphics, entraré en una página que muestre el html cuando customerUpdate = true.
EDITAR 1:
En mi app-routing.module.ts
{ path: 'anagraphics', loadChildren: () => import('./anagraphics/anagraphics.module').then(m => m.AnagraphicPageModule), canActivate: [AuthGuard], data: { configurator: true, customerUpdate: false } },pero de esta manera customerUpdate siempre está en false.
Enlace de referencia de mi solución: https://angular.io/api/router/RouterEvent
En su archivo .routing.module.ts agregue datos como los siguientes.
const routes: Routes = [{ path: '', component: AlertsComponent, data: { // What data you want to pass add that here } }]Luego obtenga ese valor en su componente común como se muestra a continuación. (Como: aplicación o componente de navegación)
constructor(public router: Router) { router.events.pipe( filter((e: Event): e is RouterEvent => e instanceof RouterEvent) ).subscribe((e: RouterEvent) => { // Get your route data here }); }