Created
January 22, 2025 10:57
-
-
Save Armenvardanyan95/731d8677e58cc81977e927b3fb4ef3fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // instead of this | |
| @Component({ | |
| template: ` | |
| @switch (country.value()) { | |
| @case ('UK') { | |
| <app-uk-payroll/> | |
| } | |
| @case ('USA') { | |
| <app-usa-payroll/> | |
| } | |
| @case ('Canada') { | |
| <app-canada-payroll/> | |
| } | |
| } | |
| `, | |
| }) | |
| export class ShellComponent { | |
| readonly #userService = inject(UserService); | |
| country = rxResource({ | |
| loader: () => this.#userService.getCountryOfResidence(), | |
| }); | |
| } | |
| // do this | |
| export function matchCountryPayroll(country: string): CanMatchFn { | |
| return () => { | |
| const userService = inject(UserService); | |
| return userService.getCountryOfResidence().pipe( | |
| map((userCountry) => userCountry === country) | |
| ); | |
| }; | |
| } | |
| export const routes: Routes = [ | |
| { | |
| path: 'payroll', | |
| canMatch: [matchCountryPayroll('UK')], | |
| component: UKPayrollComponent | |
| }, | |
| { | |
| path: 'payroll', | |
| canMatch: [matchCountryPayroll('USA')], | |
| component: USAPayrollComponent | |
| }, | |
| { | |
| path: 'payroll', | |
| canMatch: [matchCountryPayroll('Canada')], | |
| component: CanadaPayrollComponent | |
| }, | |
| ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment