Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support Angular 14 inject() #141

Closed
1 task done
jonathanwilke opened this issue Jul 19, 2022 · 2 comments
Closed
1 task done

Feature: support Angular 14 inject() #141

jonathanwilke opened this issue Jul 19, 2022 · 2 comments
Labels
enhancement New feature or request PRs welcome

Comments

@jonathanwilke
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Is this a regression?

No

Current behavior

When using Angular 14 inject() to inject the TranslocoService, the extract and find commands don't work.

Expected behavior

Should work with inject().

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-mbcpxm?file=src%2Fapp%2Fapp.component.ts

Transloco Config

No response

Debug Logs

No response

Please provide the environment you discovered this bug in

Transloco: 
Transloco Keys Manager:
Angular:
Node: 
Package Manager: 
OS:

Additional context

No response

I would like to make a pull request for this bug

No

@jonathanwilke
Copy link
Contributor Author

jonathanwilke commented Jul 19, 2022

I am not an expert in tsquery, but I managed to match the injects with this query:

const typescript = `
class Animal {
    transloco = inject(TranslocoService);
}
`;

const ast = tsquery.ast(typescript);

const injectNodes = tsquery(
  ast,
  `PropertyDeclaration:has(CallExpression:has(Identifier[name=TranslocoService],Identifier[name=inject]))`
);

console.log(injectNodes[0].name.getText());

Maybe that's helpful.

@shaharkazaz shaharkazaz added enhancement New feature or request PRs welcome labels Jul 19, 2022
@shaharkazaz shaharkazaz changed the title Bug: transloco-key-manager find not working when using inject() Feature: support Angular 14 inject() Jul 19, 2022
@andreyjamer
Copy link

Key extraction for TranslocoService injected unsing inject() function does not work on version 3.8.0. So changes from this PR #142 didn't help (

I'm using the following code:

export const hasPermissionFactory(): Observable<string> {
    const permission = inject(PermissionService);
    const translate = inject(TranslocoService);
    const snackBarManager = inject(MatSnackBar);

    return permission.hasPermissions().pipe(
        switchMap((hasPermission) => {
            if (!hasPermission) {
                return zip([
                    translate.selectTranslate(
                        'permission.snackbar.no-permission',
                    ),
                    translate.selectTranslate('permission.snackbar.close'),
                ]).pipe(
                    tap(([message, close]) => {
                        snackBarManager.open(message, close, {
                            duration: 3000,
                            horizontalPosition: 'right',
                        });
                    }),
                    map(() => false),
                );
            }
            return of(true);
        }),
    );
}

For this case permission.snackbar.no-permission and permission.snackbar.close are not extracted.
There is a workaround to add messages using marker function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PRs welcome
Projects
None yet
Development

No branches or pull requests

3 participants