Skip to content

Compiler doesn't report missing import for a directive applied on ng-template #69322

Closed

Description

@sysmat

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

Yes

Description

  • When using a standalone attribute directive in a template via property binding syntax (e.g., [myDirective]="value"), the Angular compiler completely ignores the binding if the directive is forgotten in the @Component.imports array.

  • Even with strictTemplates: true and extended diagnostics enabled, the compiler does not throw an error or warning about an unknown property on standard HTML elements (like div), provided the bound expression is a method call or a valid property.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

import { Directive, Input } from '@angular/core';

@Directive({
  selector: '[auiTypedOption]',
  standalone: true
})
export class TypedOptionDirective {
  @Input() auiTypedOption: any;
}



import { Component } from '@angular/core';

@Component({
  selector: 'app-test',
  standalone: true,
  imports: [], // <-- TypedOptionDirective is missing here
  template: `
    <div [auiTypedOption]="searchResult()"></div>
  `
})
export class TestComponent {
  searchResult() {
    return { query: 'test' };
  }
}



{
  "angularCompilerOptions": {
    "strictTemplates": true,
    "extendedDiagnostics": {
      "defaultCategory": "error",
      "checks": {
        "missingControlFlowDirective": "error"
      }
    }
  }
}

Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 21.2.14
Angular           : 21.2.17
Node.js           : 24.16.0
Package Manager   : npm 11.10.0
Operating System  : win32 x64

┌───────────────────────────────┬───────────────────┬───────────────────┐
│ Package                       │ Installed Version │ Requested Version │
├───────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/build-angular │ 21.2.14           │ ^21.2.14          │
│ @angular/build                │ 21.2.14           │ ^21.2.14          │
│ @angular/cli                  │ 21.2.14           │ 21.2.14           │
│ @angular/common               │ 21.2.17           │ 21.2.17           │
│ @angular/compiler             │ 21.2.17           │ 21.2.17           │
│ @angular/compiler-cli         │ 21.2.17           │ 21.2.17           │
│ @angular/core                 │ 21.2.17           │ 21.2.17           │
│ @angular/forms                │ 21.2.17           │ 21.2.17           │
│ @angular/language-service     │ 21.2.17           │ 21.2.17           │
│ @angular/localize             │ 21.2.17           │ ^21.2.17          │
│ @angular/platform-browser     │ 21.2.17           │ 21.2.17           │
│ @angular/router               │ 21.2.17           │ 21.2.17           │
│ @angular/service-worker       │ 21.2.17           │ 21.2.17           │
│ rxjs                          │ 7.8.2             │ ^7.8.2            │
│ typescript                    │ 5.9.3             │ 5.9.3             │
│ zone.js                       │ 0.16.2            │ ~0.16.2           │
└───────────────────────────────┴───────────────────┴───────────────────┘

Anything else?

Because TypedOptionDirective is not imported, the template compiler should evaluate [auiTypedOption] as a plain property binding on a div element. Since HTMLDivElement does not have a auiTypedOption property, strictTemplates should catch this and throw:
NG8002: Can't bind to 'auiTypedOption' since it isn't a known property of 'div'.

Activity

  1. added this to the needsTriage milestone on Jun 12, 2026
  2. added this to the needsTriage milestone on Jun 12, 2026
  3. kle-pra commented on Jun 12, 2026

    @kle-pra

    I experience this problem as well, it would be great if this could be fixed.

  4. JeanMeche commented on Jun 12, 2026

    @JeanMeche
    Member

    I'm getting Can't bind to 'auiTypedOption' since it isn't a known property of 'div'.ngtsc(-998002) with your example. $

    Please provide a repro.

  5. added
    needs reproductionThis issue needs a reproduction in order for the team to investigate further
    on Jun 12, 2026
  6. modified the milestones: needsTriage, Backlog on Jun 12, 2026
  7. sysmat commented on Jun 13, 2026

    @sysmat
    Author
    • @JeanMeche my bad of reproducing the bug. Also I get the same error

    • Here is better.

    • directive

    import { Directive, input } from '@angular/core';
    
    @Directive({
      selector: 'ng-template[auiTypedOption]',
      standalone: true
    })
    export class TypedOptionDirective {
      auiTypedOption = input.required<any>();
    }
    • usage
    <ng-template [auiTypedOption]="searchResult()"></ng-template>
    ...
    searchResult = signal({ name: 'test' });
  8. changed the title [-]bug(compiler): strictTemplates fails to report unknown property binding when a standalone directive is missing from component imports[/-] [+]Compiler doesn't report missing import for a directive applied on `ng-template`[/+] on Jun 15, 2026
  9. 19 remaining items

  10. added a commit that references this issue on Aug 29, 2026
    baeffad
  11. added a commit that references this issue on Sep 14, 2026
    be80734
  12. added a commit that references this issue on Sep 30, 2026
    c7ab8ad
  13. added 2 commits that reference this issue on Oct 25, 2026
    98ffc53
    bd619ed
  14. added 8 commits that reference this issue on Nov 8, 2026
    0eb6778
    a6b9510
    4ad60dc
    738837a
    55860b3
    49205c8
    7dc15b4
    39a5e0d
  15. added a commit that references this issue on Nov 11, 2026
    e4f6744
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions