Skip to content

fix(compiler): inject @Attribute() params with ɵɵinjectAttribute outside components - #625

Open
edbzn wants to merge 1 commit into
voidzero-dev:mainfrom
edbzn:fix/attribute-inject
Open

edbzn wants to merge 1 commit into
voidzero-dev:mainfrom
edbzn:fix/attribute-inject

Conversation

@edbzn

@edbzn edbzn commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #624.

Problem

For @Directive, @Pipe, @Injectable and @NgModule, the constructor param extractors set attribute_name_type to the parameter's type token. For @Attribute('title') t: string that is None, so compile_inject_dependency emitted ɵɵdirectiveInject("title") / ɵɵinject("title") and Angular resolved "title" as a DI token (NullInjectorError: No provider for title!). Components were unaffected because they use a separate dependency path.

Fix

Set attribute_name_type to the attribute name literal in the four extractors, as ngtsc does in ngtsc/annotations/common/src/di.ts (attributeNameType = new LiteralExpr(attributeName.text)). compileInjectDependency in render3/r3_factory.ts then emits ɵɵinjectAttribute whatever the target. As a side effect, string-typed @Attribute params now also get attribute: true in partial declarations and an attribute entry in the .d.ts ctor deps type, which they were missing.

Checks

  • New tests/attribute_inject_test.rs: directive_factory_injects_the_attribute, pipe_factory_injects_the_attribute, injectable_factory_injects_the_attribute, ng_module_factory_injects_the_attribute (all fail on main).
  • cargo test -p oxc_angular_compiler --all-features: 3520 passed, 0 failed.

🤖 Generated with Claude Code

…outside components

Directive, pipe, injectable and NgModule factories took `attributeNameType`
from the parameter's type, which is unset for `string`, so the attribute name
was injected as a DI token. Use the attribute name literal like ngtsc's di.ts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.

fix(compiler): @Attribute() on a directive/pipe/injectable/NgModule constructor compiles to a token inject (NullInjectorError)

1 participant