1

I have a few simple helper directives which I want to use throughout the entire app. With modules this was easy to do, but with standalone I don't know how we can do it.

One example of such a simple helper directive is:

@Directive({
 selector: '[click]',
 standalone: true,
 host: {
 class: 'on-click',
 tabindex: '0',
 },
})
export class ClickEventDirective {}

Every single component in the app that uses a (click)="clickHandler()" somewhere should have this applied. I was thinking of something like this, but it should trickle down to all child components.

@Component({
 selector: 'app',
 template: `
 <router-outlet />
 `,
 standalone: true,
 imports: [
 ClickEventDirective,
 ...
 ],
})
asked Apr 2, 2025 at 9:31
1
  • only providers can be provided globally not components or directives, so it is not possible Commented Apr 2, 2025 at 9:34

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.