Make standalone Directive `selector` optional

This issue has been created since 2022-11-17.

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

core

Description

With Angular 15 host directives it is now possible to have directives that are only used to augment another component or directive via the directive composition API. These directives are never imported or used in a template, making the selector redundant. It would be nice if the selector could be omitted for this use case.

Proposed solution

Allow standalone directives to omit the selector. This should be valid when the directive is used in hostDirectives, but should report a compilation error if you try to import it due to the missing template selector.

@Directive({ standalone: true })
class PrivateDirective {}

@Component({
  imports: [PrivateDirective], // compilation error
  hostDirectives: [PrivateDirective] // allowed
})
export class AppComponent {}

Alternatives considered

Make up a random selector name so it doesn't conflict with other directives.

JoostK wrote this answer on 2022-11-17

Did you test this by any chance? Directives without selector are allowed when I just tested this; we don't report an error for including said directive in imports at the moment, that seems like a bug to me.

antischematic wrote this answer on 2022-11-17

You're right, I just checked again and it works without the selector. It was just IntelliJ marking the missing selector as an error in the editor 🤦

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2022-12-01
Star Count 85220
Watcher Count 3042
Fork Count 22607
Issue Count 1316

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Support WAVE_FORMAT_MULAW 1 2021-07-14 2022-11-22
[question] zwavejs2mqtt container starts then shuts down on reboot 5 2022-08-30 2022-11-13
群晖docker版本在运行超过一定时间后,无法正常录制,在docker管理器中重启后恢复正常 9 2022-08-14 2022-11-15
Alignment Issues with Windows Display Scaling 4 2021-02-09 2022-11-03
No forward button to match the Back button styling? 0 2022-08-08 2022-11-06
missing sensor(s) on update 4 2021-11-22 2022-07-19
sea level and station pressure inverted 4 2021-11-22 2022-07-19
do not see in config>integations page 2 2021-07-27 2022-07-19
[OTHER] Some non-inclusive words 0 2022-04-26 2022-11-22
Mistake in arduinojson.org FAQ 1 2021-11-15 2022-11-23
Authentication Issues - Multiple Extensions 2 2022-09-20 2022-10-07
Whole season manual imports from manual NZB copy, then delete, instead of hard link 3 2022-05-16 2022-10-27
Fatal Error Unable to create lock file: Bad file descriptor (9) 4 2020-11-14 2022-11-11
Add Custom Dataloader Example into template 3 2022-09-29 2022-11-13
How to define a conditional search space ? 8 2022-10-18 2022-11-13
Enable snapshot tests on Linux 0 2022-02-06 2022-10-03
Modify shell startup file PBA Windows 1 2022-04-01 2022-11-02
Want audio/video recording dynamically 2 2021-09-03 2022-11-22
Tanzu CLI should provide a better response when trying to retrieve a token (auth) when identity management is not turned on 2 2021-10-11 2022-08-31
Mousemovement Performance improvement 2 2022-04-26 2022-11-17
Geometry Wars TODO List 0 2017-08-22 2022-11-06
Passing arguments with pushNamed is alway null 0 2021-10-26 2022-11-15
Show trustworthiness and virusscan status in the GUI 0 2021-01-18 2022-11-19
Consider mapping wikidata keys, OSM IDs in OSM responses 4 2022-02-27 2022-11-05
Remove the need for conda-forge to be patched at release time 2 2022-09-27 2022-11-08
can't install mpd file 1 2021-12-03 2022-09-20
SysV init scripts of ::daemon are broken 2 2021-02-11 2022-11-15
已收藏的 icon 在哪里找 ? [Help] 1 2021-06-23 2022-11-05
metrics: add csv output format results to memory-usage-inside-container 0 2022-09-08 2022-11-13
Menu Entity Swapper - Remove dead npc menus 1 2022-06-19 2022-10-02
uninitialised PackedCandidate mass() 10 2021-12-16 2022-10-23
TestIntegrationFinalPath failure 19 2021-12-16 2022-11-05
[bitnami/redis-cluster] Kubernetes - I can't connect my app to the cluster 2 2021-11-19 2022-06-28
mui.com crash on Safari 3 2021-12-21 2022-11-06
OpenTracing Providers found multiple times (RESTEASY002160) 3 2021-12-07 2022-08-28
Question: when will it release new version? 1 2021-03-18 2022-11-13
Advanced transformation of Code Blocks using HotTable 1 2022-03-16 2022-11-01
CMake fails with `The dependency target "benchmark" of target "libc-benchmark" does not exist.` 3 2022-02-09 2022-08-11
sdf param of map.addImage not working correct 0 2021-08-10 2022-11-26
[iOS][0.30.1] image组件,设置userInteractionEnabled不生效 2 2022-06-10 2022-11-22
[Query] I am not able to set password parameters with job.build(params) 3 2019-06-19 2022-10-24
How to achieve idempotence for incoming events 2 2022-01-07 2022-11-05
Query error: The specified configuration cannot be used. 0 2021-11-08 2022-10-21
Four extensions that I did not install appear on a remote server when connected with vscode.dev 3 2022-10-08 2022-10-18
dotfile clone from azure devops repo: "fatal: Cannot determine the organization name..." 0 2022-10-09 2022-10-18
SemanticTokens Edits not performant in large documents 4 2022-03-11 2022-10-25
Debug panic in fmt if there is a tab in a comment 5 2021-09-24 2022-11-05
Allow renaming files on the remote host in the file transfer window 2 2022-11-10 2022-11-17
Safe area in bottom 4 2021-02-03 2022-01-16
ImportError: cannot import name '_Task' from 'pp' 4 2022-08-01 2022-11-22