Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Angular 18 OnInit paramMap

46 views
Skip to first unread message

Tong Phou

unread,
Oct 9, 2024, 11:50:20 PM10/9/24
to Angular and AngularJS discussion
here is my code (header with bootstrap Nav):
```
<li class="nav-item dropdown">
  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
    Photos
  </a>
  <ul class="dropdown-menu">
    <li *ngFor="let p of photoMenu">
      <a class="dropdown-item" [routerLink]="['/photos', p.param]">{{ p.title }}</a>
      <!--<a class="dropdown-item" *ngFor="let p of photoMenu" routerLink="/photos/{{p.param}}">{{ p.title }}</a>-->
    </li>
  </ul>
</li>
```
```
  public ngOnInit(): void {
    this.paramsSub = this.activedRoute.paramMap
      .subscribe(
        (params: any | ParamMap) => {
          this.val.photoFolder = params.get('folder'),
            this.val.fileFolder = this.mediaConfig.AssetPhotoFolder + "/" + params.get('folder') + "/";
          this.photoParam = this.val;
          /* this.route.navigateByUrl(this.route.url);*/
          this.route.navigateByUrl('/');
          this.route.navigateByUrl(this.route.url);
        }
      )
  }
```
Every time the p.param value in the header change, the app oninit is not executed.(it runs only one time on the first time).  I did put the onload in the contruction but it did not work either.

I seen this issue occured in the previous version.  However, I tried to use it with the new angular 18 standalone version.   I wonder....
I did something wrong or it is still a bug in Angular Standalone?

Is there a work around?

Thanks.

Reply all
Reply to author
Forward
0 new messages