navbar dynamique

pull/2/head
Maxence JOUANNET 5 months ago
parent d7dc8f5e39
commit d24171607b

@ -1,23 +1,24 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { NgIf } from '@angular/common'; import { NgIf } from '@angular/common';
import { Router, NavigationEnd } from '@angular/router';
@Component({ @Component({
selector: 'app-navbar', selector: 'app-navbar',
imports: [NgIf], imports: [NgIf],
templateUrl: './navbar.component.html', templateUrl: './navbar.component.html',
}) })
export class NavbarComponent { export class NavbarComponent implements OnInit {
isHomePage: boolean = false; isHomePage: boolean = false;
constructor() { constructor(private router: Router) {}
}
ngOnInit(): void { ngOnInit(): void {
let url = window.location.pathname; this.isHomePage = this.router.url === '/';
if (url === '/') { this.router.events.subscribe((event) => {
this.isHomePage = true; if (event instanceof NavigationEnd) {
} this.isHomePage = event.url === '/';
}
});
} }
} }

Loading…
Cancel
Save