I am subscribing to my route params in angular but it keeps returning two values (the previous url and the present one), which messes up my code. I tried using the take operator to return only one instance of the params, but it returns the previous url instead.
Update: I edited the code to use the skip operator and the take operator and this time it does return the right params, but it still runs more than once which causes the array duplication and if I try to route to the same route again (which my situation requires), it doesn't get any params because I am skipping the first value
this.route.params.pipe(skip(1), take(1)).subscribe((params) => {
console.log(params);
if (params) {
this.subscription = this.chatService.oneChannel(params['id']).subscribe((channel) => {
this.channel = channel!;
for (let i = 0; i < this.channel?.members!.length; i++) {
this.chatService.getUserData(this.channel?.members![i]).pipe(take(1)).subscribe(result => {
this.members.push(result!);
})
}
})
}
})