Skip to content

fix(factory): inject string tokens of @Inject('TOKEN') in component factories - #599

Open
Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/inject-string-token
Open

Rush wants to merge 1 commit into
voidzero-dev:mainfrom
encharm:fix/inject-string-token

Conversation

@Rush

@Rush Rush commented Oct 21, 2026

Copy link
Copy Markdown

A component constructor parameter decorated with a string token, @Inject('API_URL'), compiled to ɵɵinvalidFactoryDep(index), so creating the component threw at runtime. Directives, pipes and injectables already injected the string.

Like ngtsc, the component factory now injects the string itself, with the parameter's other flags:

@Component({ selector: 'a-cmp', template: '' })
export class ACmp {
  constructor(@Inject('API_URL') url: string, @Optional() @Self() @Inject('FLAGS') flags: string[]) {}
}
// before
return new (__ngFactoryType__ || ACmp)(i0.ɵɵinvalidFactoryDep(0), i0.ɵɵinvalidFactoryDep(1));
// after, as @angular/compiler-cli 21.0.1 compiles it
return new (__ngFactoryType__ || ACmp)(i0.ɵɵdirectiveInject('API_URL'), i0.ɵɵdirectiveInject('FLAGS', 10));

tests/inject_string_token_test.rs checks the component, directive, pipe and injectable factories against ngc's output for the same classes; the component case fails without the change.

…actories

A component constructor parameter decorated with `@Inject('TOKEN')` compiled to
`ɵɵinvalidFactoryDep(index)`, so creating the component threw. Like ngtsc, the
factory now injects the string itself: `ɵɵdirectiveInject('TOKEN')`, with the
parameter's other flags (`@Optional()`, `@Self()`, ...). Directives, pipes and
injectables already did.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant