The url looks like this:
http://localhost:4200/room/RECd4teOsdsro9YRcOMX/chat
I'm trying to extract the id part (RECd4teOsdsro9YRcOMX)
I tried the following:
chatRoomUid: string;
constructor(
private route: ActivatedRoute
) {}
ngOnInit() {
this.chatRoom$ = this.route.parent.parent.params.pipe(
tap(params => this.chatRoomUid = params.chatRoomUid),
switchMap(params => {
if (!params.chatRoomUid) return of(null);
this.chatRoomUid = params.chatRoomUid;
})
);
console.log(this.chatRoomUid); // returns undefined
}
How can I extract the id from the url and save it to my variable chatRoomUid
?
Route:
{ path: 'room/:roomUid', loadChildren: () => import('@chatapp/pages/room/room.module').then(m => m.RoomModule) },
Edit: Added the routes