Skip to content

Instantly share code, notes, and snippets.

@andrewarosario
Last active February 25, 2021 01:21
Show Gist options
  • Save andrewarosario/ee2520414959d4ec7aa418fff3bff66f to your computer and use it in GitHub Desktop.
Save andrewarosario/ee2520414959d4ec7aa418fff3bff66f to your computer and use it in GitHub Desktop.
export const USER_DETAIL = new InjectionToken<Observable<User>>(
'A stream with current user detail'
);
export const USER_PROVIDERS: Provider[] = [
{
provide: USER_DETAIL,
deps: [ActivatedRoute, UserService],
useFactory: userFactory,
},
];
export function userFactory(
route: ActivatedRoute,
userService: UserService
): Observable<User> {
return route.paramMap.pipe(
switchMap((params) => {
const id = params.get('orgId');
return userService.getById$(id);
})
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment