2

In my routes.ts I have { path: 'members', component: MemberListComponent, resolve: { users: MemberListResolver} },.

I have the following piece of code in my component:

  users: User[];

  constructor(private route: ActivatedRoute, private authService: AuthService) { }

  ngOnInit() {
    this.route.data.subscribe((data) => {
      this.users = data.users.filter((u: User) => u.id !== +this.authService.decodedToken.nameid);
    });
  }

I'm doing the filter in the subscribe method, is it also possible to do this in a pipe, if so how would I do it?

sdfsd
  • 1,043
  • 1
  • 8
  • 13

1 Answers1

2

Thanks to @JB Nizet's comment I solved it like:

  ngOnInit() {
    this.route.data
      .pipe(map(data => data.users.filter((u: User) => u.id !== +this.authService.decodedToken.nameid)))
      .subscribe((data) => {
        this.users = data;
      });
  }
sdfsd
  • 1,043
  • 1
  • 8
  • 13