Skip to content

Add @Directive metadata to disallow template bindings to properties or events #62689

@robmv

Description

@robmv

Which @angular/* package(s) are relevant/related to the feature request?

compiler-cli

Description

Sometimes directives are created to simplify repetitive behaviors that clash with using the host element properties or events directly, for example a myButtonStyle directive that don't want the user to add class or style attributes directly to the button elements. Or a myButtonAction that internally listen to click events and don't want users of the directive to use click bindings on the template.

Proposed solution

Allow something like:

@Directive({
  selector: 'button[myButtonStyle]',
  reject: ['class', 'style'],
})

For the properties case, or:

@Directive({
  selector: 'button[myButtonAction]',
  reject: ['(click)'],
})

For the events case.

Alternatives considered

For the properties case, defining an input of type never works, but there is no way to indicate the user the reason why using style on the template is discouraged by the directive author.

readonly style = input<never>();

There is no alternative for the output or events case.

Note: The proposed solution nor the alternative has a way to discourage directly using the DOM to set properties or add listeners, but this is true too for everything the templating engine does, so adding these checks to the template compiler can be useful on the template authoring workflow

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy